【问题标题】:With C# / Winforms / GDI+, how do i do getpixel or getimage of a control?使用 C#/Winforms/GDI+,如何获取控件的 getpixel 或 getimage?
【发布时间】:2010-08-02 22:37:42
【问题描述】:

我想在我的 winforms 对话框中“抓取”控件的图像。我可以使用以下方法访问控件的“图形”上下文:

MyControl.CreateGraphics()

但是我如何将矩形从该图形上下文复制到图像或位图,或调用 getpixel 呢?

非常感谢。

【问题讨论】:

  • 我使用 MyControl.DrawToBitmap 取得了一些骇人听闻的成功,这是一个好方法吗?还是有更好的选择?

标签: winforms gdi+


【解决方案1】:

我认为 MyControl.DrawToBitmap 是要走的路:

Bitmap bmp = new Bitmap(MyControl.Width, MyControl.Height);
MyControl.DrawToBitmap(bmp, MyControl.ClientRectangle);

如果您需要获取像素,请使用 Bitmap.GetPixel 或 Bitmap.LockBits

【讨论】:

    猜你喜欢
    • 2011-06-07
    • 1970-01-01
    • 2011-09-17
    • 2023-03-13
    • 2014-10-14
    • 1970-01-01
    • 2021-07-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多