C++怎么获得屏幕上点的颜色

如题所述

GetPixel函数
hdc=GetDC(hwnd);
GetCursorPos(&mspt);
handle=WindowFromPoint(mspt);
GetWindowRect(handle,&d_rect);
color=GetPixel(GetWindowDC(handle),mspt.x-d_rect.left,mspt.y-d_rect.top);
这段代码可以得到鼠标点的颜色,在color中。
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2016-05-14
COLORREF clr = ::GetPixel(hDC, point.x, point.y); //获取当前鼠标点像素值
m_red = GetRValue(clr);
m_bluee = GetBValue(clr);
m_green = GetBValue(clr);
第2个回答  2009-07-19
//全局变量
int x,y;
int r ,g,b ;
COLORREF up;
char text[32];

case WM_LBUTTONDOWN:
x = LOWORD(lParam);
y = HIWORD(lParam);
up = GetPixel(GetDC(hWnd),x,y); //得到点的RGB颜色
r = GetRValue(up); //返回R的颜色值!
g = GetGValue(up); //返回G的颜色值!
b = GetBValue(up); //返回B的颜色值!
sprintf_s(text, "R:%d, G %d, B %d ", r,g,b);
OutputDebugString(text);
MessageBox(NULL,text , "坐标颜色值", MB_OK);

break;
第3个回答  2009-07-18
.. .. 这得用到系统函数.. . 具体的就不晓得了.
相似回答