MFC获得屏幕上任意一点的像素值

来源:互联网 发布:mac地址修改器win10 编辑:程序博客网 时间:2024/05/16 16:01

使用CWindowDC获得屏幕任意一点point的像素值:

CWindowDC dc(GetDesktopWindow());

COLORREF color = dc.GetPixel(point);     //获得点point的颜色值

int Red=GetRValue(color);         //获得红色值
int Green=GetGValue(color);    //获得绿色值
int Blue=GetBValue(color);      //获得蓝色值

 

如果需要取得鼠标的位置,有3种方法,一种是使用定时器,不停的GetCursorPos(&point)获取鼠标位置.另外一种是使用钩子,获取鼠标的按下,放开,移动消息。还有一种是在鼠标按下时使用SetCaputrue,然后在MouseMove中得到点,在鼠标放开时使用ReleaseCaputure。

 

在这里有自己用VC6.0写的一个颜色采集器小工具:

http://download.csdn.net/detail/zengweicdut/5250731

软件界面: