我正在做这个油漆应用程序。这有点简单。它包含一个面板,我将在其中绘图,最后我将另存为 JPG、BMP 或 PNG 文件。
我的应用程序运行完美,但我面临的问题是,当我保存输出时,面板上绘制的不是黑色图像,而是黑色。
我所有的工作都被保存为
Thepic = new Bitmap(panel1.ClientRectangle.Width, this.ClientRectangle.Height);
在鼠标上(向下,向上)我有
snapshot = (Bitmap)tempDraw.Clone();
它正常保存了工作,但结果再次是黑色图像,而不是面板包含的图像。
最佳答案
我认为问题可能在于您使用的是“克隆”方法。
试试“DrawToBitmap”——这在过去对我有用。
这是一个从名为“plotPrinter”的控件中保存位图的示例:
int width = plotPrinter.Size.Width;
int height = plotPrinter.Size.Height;
Bitmap bm = new Bitmap(width, height);
plotPrinter.DrawToBitmap(bm, new Rectangle(0, 0, width, height));
bm.Save(@"D:\TestDrawToBitmap.bmp", ImageFormat.Bmp);
Be aware of saving directly to the C directly as this is not permitted with newer versions of window, try using SaveFileDialog.
SaveFileDialog sf = new SaveFileDialog();
sf.Filter = "Bitmap Image (.bmp)|*.bmp|Gif Image (.gif)|*.gif|JPEG Image (.jpeg)|*.jpeg|Png Image (.png)|*.png|Tiff Image (.tiff)|*.tiff|Wmf Image (.wmf)|*.wmf";
sf.ShowDialog();
var path = sf.FileName;
关于c# - 将面板保存为图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1836338/