Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Question about bitmap saving in .NET

Tags:

c#

.net

bitmap

I have a bitmap object and draw some curves on it by setpixel method. when I save this bitmap as jpg file, the background of my picture is not a white surface. the background is transparent. what is the problem? How can I resolve this problem?

like image 247
masoud ramezani Avatar asked Jun 11 '26 18:06

masoud ramezani


1 Answers

Call Graphics.Clear(Color.White) before you draw on the bitmap. If you do not already have an instance of System.Drawing.Graphics for your bitmap, here's how to get one:

Graphics g = Graphics.FromImage(bitmap);

Clear the bitmap:

g.Clear(Color.White);

And of course, don't forget to call Dispose() when you are done with the graphics.

g.Dispose();
like image 153
Zach Johnson Avatar answered Jun 14 '26 09:06

Zach Johnson