背景打开黑色当保存位图 - C# [英] Background Turns Black When Saving Bitmap - C#
问题描述
目前我正在试图挽救一个位图图像,但背景正在改变为黑色。
我可以在另存为的形象完美的罚款。我也可以拯救的形象为好。这是更为困难,因为我不得不覆盖现有的图像。
然而,当我拯救我的形象的背景变黑。我不知道是什么原因造成的。
下面是我的code:
位图tempImage =新位图(DrawArea);DrawArea.Dispose();如果(扩展名==.JPEG)
tempImage.Save(文件名,System.Drawing.Imaging.ImageFormat.Jpeg);
其他
tempImage.Save(文件名,System.Drawing.Imaging.ImageFormat.Bmp);DrawArea =新位图(tempImage);
pictureBox1.Image = DrawArea;tempImage.Dispose();
创建一个空白位图。创建一个图形对象与空白位图写。清除位图,并改变其颜色为白色。然后绘制图像,然后保存该位图。
位图空白=新位图(DrawArea.Width,DrawArea.Height);
图形G = Graphics.FromImage(空白);
g.Clear(Color.White);
g.DrawImage(DrawArea,0,0,DrawArea.Width,DrawArea.Height); 位图tempImage =新位图(空白);
blank.Dispose();
DrawArea.Dispose(); 如果(扩展名==.JPEG)
tempImage.Save(文件名,System.Drawing.Imaging.ImageFormat.Jpeg);
其他
tempImage.Save(文件名,System.Drawing.Imaging.ImageFormat.Bmp); DrawArea =新位图(tempImage);
pictureBox1.Image = DrawArea; tempImage.Dispose();
I am currently trying to save a bitmap image, but the background is changing to black.
I can "Save As" the image perfectly fine. I can also "Save" the image as well. Which was much more difficult because I had to overwrite the existing image.
However, when I "save" my image the background is turning black. And I have no idea what is causing it.
Here is my code:
Bitmap tempImage = new Bitmap(DrawArea);
DrawArea.Dispose();
if (extension == ".jpeg")
tempImage.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg);
else
tempImage.Save(fileName, System.Drawing.Imaging.ImageFormat.Bmp);
DrawArea = new Bitmap(tempImage);
pictureBox1.Image = DrawArea;
tempImage.Dispose();
Create a blank bitmap. Create a graphics object to write on with that blank bitmap. Clear the bitmap and change its color to white. Then draw the image then save the bitmap.
Bitmap blank = new Bitmap(DrawArea.Width, DrawArea.Height);
Graphics g = Graphics.FromImage(blank);
g.Clear(Color.White);
g.DrawImage(DrawArea, 0, 0, DrawArea.Width, DrawArea.Height);
Bitmap tempImage = new Bitmap(blank);
blank.Dispose();
DrawArea.Dispose();
if (extension == ".jpeg")
tempImage.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg);
else
tempImage.Save(fileName, System.Drawing.Imaging.ImageFormat.Bmp);
DrawArea = new Bitmap(tempImage);
pictureBox1.Image = DrawArea;
tempImage.Dispose();
这篇关于背景打开黑色当保存位图 - C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!