c# - 将面板保存为图像

标签 c# drawing

我正在做这个油漆应用程序。这有点简单。它包含一个面板,我将在其中绘图,最后我将另存为 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/

相关文章:

c# - 林克 "Could not translate expression... into SQL and could not treat it as a local expression."

c# - 检查隐藏的 bool 值以运行方法

c# - 将日期从 View 传递到 Controller mvc/c#

graphics - 透明位图

android - PDFTron for android - 绘制注释错误

c# - 类型名称 {myUserControl} 在类型 {myNamespace.myNamespace} 中不存在

c# - 在 C# 中禁用屏幕保护程序和电源选项

c++ - 是否可以仅使用循环在形状内绘制形状?如果是这样,请指出正确的方向

c - 更改窗口大小后重新绘制/刷新

math - 如何从鼠标手势生成的点列表中确定所有线段?