C#简单获取屏幕鼠标坐标点颜色
api函数:1 //取设备场景2 private static extern IntPtr GetDC(IntPtr hwnd);//返回设备场景句柄
3
4 //取指定点颜色
5 private static extern int GetPixel(IntPtr hdc, Point p);
主要方法:Timer tim = new Timer();
tim.Interval = 1;
tim.Tick += delegate
{
Point p = new Point(MousePosition.X, MousePosition.Y);//取置顶点坐标
IntPtr hdc = GetDC(new IntPtr(0));//取到设备场景(0就是全屏的设备场景)
int c = GetPixel(hdc, p);//取指定点颜色
int r = (c & 0xFF);//转换R
int g = (c & 0xFF00) / 256;//转换G
int b = (c & 0xFF0000) / 65536;//转换B
pictureBox1.BackColor = Color.FromArgb(r, g, b);
};
tim.Start();
效果演示:http://pic002.cnblogs.com/images/2012/435774/2012110611340894.gif
转自:http://www.cnblogs.com/xhk-yjp/archive/2012/11/06/xhk-qs.html
页:
[1]