开发者

Question about bitmap saving in .NET

开发者 https://www.devze.com 2022-12-20 22:00 出处:网络
I have a bitmap object and draw some curves on it by setpixel method. when I save this bitmap as jpg file, t开发者_如何学JAVAhe background of my picture is not a white surface. the background is trans

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


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();


Are you certain that you are saving the image out in JPEG format? AFAIK, JPEG doesn't support transparancy, so perhaps you're saving the image out as GIF or PNG with a ".jpg" extension, and your viewer is ignoring the extension.

In any case, Zach's solution should fill your bitmap with a solid background color before you start drawing.

0

精彩评论

暂无评论...
验证码 换一张
取 消