【问题标题】:get color of a panel获取面板的颜色
【发布时间】:2012-02-20 06:20:16
【问题描述】:

如何获取Panel(或其他任何东西,例如Form)的像素颜色?
(我可以用Graphics的函数来做吗?)

提前谢谢你。

【问题讨论】:

标签: c# .net winforms


【解决方案1】:

基于here提供的代码,
我创建了一个扩展方法,它返回控制像素的颜色,给定像素的客户端坐标:

public static class ControlExts
{
    public static Color GetPixelColor(this Control c, int x, int y)
    {
        var screenCoords = c.PointToScreen(new Point(x, y));
        return Win32.GetPixelColor(screenCoords.X, screenCoords.Y);
    }
}

所以,在你的情况下,你可以这样做:

var desiredColor = myForm.GetPixelColor(10,10);

【讨论】:

    猜你喜欢
    • 2011-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-17
    • 2021-11-07
    相关资源
    最近更新 更多