【问题标题】:How to get bitmap from painted panel in C#如何从 C# 中的绘制面板获取位图
【发布时间】:2011-12-18 18:28:13
【问题描述】:

我有一个面板,我使用它的 Graphics gr = panel1.CreateGraphics() 来绘制线条和其他东西。我需要获取鼠标点击点的像素颜色,所以我决定使用 Bitmap 的 GetPixel 方法。我这样创建位图:

Bitmap b = new Bitmap(width, height);            
panel1.DrawToBitmap(b, new Rectangle(0, 0, width, height));
b.Save("D:/aaa.bmp");

但即使我画了任何东西,我也只能得到白色矩形。有什么问题?

【问题讨论】:

标签: c# graphics bitmap system.graphics


【解决方案1】:

只有在Paint 事件中绘制的东西才会由DrawToBitmap 呈现。不要显式调用panel1.CreateGraphics(),而是处理面板的Paint 事件并使用e.Graphics 进行绘图。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多