Hi to all I hope you can help with the following issue I have, thanks in advance.
I'm working in an application that insert text to pictures.
The problem is that after inserting the text, the size of the new pictures is smaller(in KB). I'll explain myself the original picture its size is 468KB and after inserting the text the new picture has the size 93KB. I'm wandering why the picture is smaller, I'm guessing I'm loosing quality or something else, but I don't know what (BTW the picture stay with the same dimensions (1024x768)).
This is the code I'm working to insert the text

Bitmap bitmap = new Bitmap(@"C:\pics\mypic.jpg");
Graphics g = Graphics.FromImage(bitmap);
//Set quality to High
g.CompositingQuality = CompositingQuality.HighQuality;
g.SmoothingMode = SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
//String to draw in Picture
g.DrawString("Text in Picture", new Font("verdana", 12), SystemBrushes.WindowText, 0, 0);
//New name of the new picture with text
bitmap.Save(@"C\pics\mypicwithtext.jpg", bitmap.RawFormat);

Thanks

Recommended Answers

All 3 Replies

Hi to all I hope you can help with the following issue I have, thanks in advance.
I'm working in an application that insert text to pictures.
The problem is that after inserting the text, the size of the new pictures is smaller(in KB). I'll explain myself the original picture its size is 468KB and after inserting the text the new picture has the size 93KB. I'm wandering why the picture is smaller, I'm guessing I'm loosing quality or something else, but I don't know what (BTW the picture stay with the same dimensions (1024x768)).
This is the code I'm working to insert the text

Bitmap bitmap = new Bitmap(@"C:\pics\mypic.jpg");
Graphics g = Graphics.FromImage(bitmap);
//Set quality to High
g.CompositingQuality = CompositingQuality.HighQuality;
g.SmoothingMode = SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
//String to draw in Picture
g.DrawString("Text in Picture", new Font("verdana", 12), SystemBrushes.WindowText, 0, 0);
//New name of the new picture with text
bitmap.Save(@"C\pics\mypicwithtext.jpg", bitmap.RawFormat);

Thanks

try writting the string on the image but comment out the quality settings and save, i do believe it is due to that the image size is changing.

When i save an image using Bitmap.save("someimage", rawformat) the image size does not change, but i also do not specify any settings for the visual appearance.

The Problem is using the method

g.DrawString("Text in Picture", new Font("verdana", 12), SystemBrushes.WindowText, 0, 0);

I put the settings for visual appearance in remarks and still get the same problem.
When not using the method DrawString and only saving the file with Bitmap.save the picture stay with the same size.
Why the method DrawString is resizing my picture?
Thanks

The Problem is using the method

g.DrawString("Text in Picture", new Font("verdana", 12), SystemBrushes.WindowText, 0, 0);

I put the settings for visual appearance in remarks and still get the same problem.
When not using the method DrawString and only saving the file with Bitmap.save the picture stay with the same size.
Why the method DrawString is resizing my picture?
Thanks

i would assume that because you are drawing on the image when you save the image the compression is re-applied to the image.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.