I am using the code below to generate a watermarked image, The problem is, the genrated file is always more bigger than the original file even if the dimensions of the generated file are smaller, for example:
original.jpg (1920 * 1440) = 1.11 MB
generated.jpg (960 * 720) = 1.77 MB
Am I missing something?
C# :
private void AddWaterMark(string target, string NewName, string newwidth, string newheight)
{
Image imgToResize = Image.FromFile(Path.Combine(target, NewName));
Bitmap indexedImage = new Bitmap(imgToResize, newwidth, newheight);
Graphics g = Graphics.FromImage(indexedImage);
g.DrawImage(indexedImage, new Rectangle(0, 0, newwidth, newheight), 0, 0, indexedImage.Width, indexedImage.Height, GraphicsUnit.Pixel);
g.RotateTransform(-35);
g.DrawString("WWW.example.COM", new Font("Verdana", 24, FontStyle.Bold), new SolidBrush(Color.FromArgb(75, 255, 255, 255)), -100, 350);
imgToResize.Dispose();
indexedImage.Save(target + "\\" + NewName);
indexedImage.Dispose();
g.Dispose();
}
VB:
Private Sub AddWaterMark(target As String, NewName As String, newwidth As String, newheight As String)
Dim imgToResize As Image = Image.FromFile(Path.Combine(target, NewName))
Dim indexedImage As New Bitmap(imgToResize, newwidth, newheight)
Dim g As Graphics = Graphics.FromImage(indexedImage)
g.DrawImage(indexedImage, New Rectangle(0, 0, newwidth, newheight), 0, 0, indexedImage.Width, indexedImage.Height, GraphicsUnit.Pixel)
g.RotateTransform(-35)
g.DrawString("WWW.example.COM", New Font("Verdana", 24, FontStyle.Bold), New SolidBrush(Color.FromArgb(75, 255, 255, 255)), -100, 350)
imgToResize.Dispose()
indexedImage.Save(target + "\" + NewName)
indexedImage.Dispose()
g.Dispose()
End Sub
You need to specify a quality, e.g.:
and using this method: