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

来源:百度知道 编辑:UC知道 时间:2024/06/23 23:27:31

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中。

//全局变量
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;

COLORREF clr = ::GetPixel(hDC, point.x, point.y); //获取当前鼠标点像素值
m_red = GetRValue(clr);
m_bluee = GetBValue(clr);
m_green = GetBValue(clr);

.. .. 这得用到系统函数.. . 具体的就不晓得了.