我的当前代码从当前光标位置读取getPixel,但返回值只是COLORREF的一些疯狂值,我希望它是RGB格式。我查看了Microsoft Reference,发现了RGB Macro
COLORREF RGB(
BYTE byRed,
BYTE byGreen,
BYTE byBlue
);
我的问题是我应该如何使用GetPixel返回到此RGB函数然后打印值? 目前的代码:
include <Windows.h>
include <wingdi.h>
include <iostream>
pragma comment(lib, "gdi32.lib")
int main() {
while (true) {
HDC hDC;
hDC = GetDC(NULL);
POINT p;
GetCursorPos( & p);
int cx = p.x;
int cy = p.y;
std::cout << GetPixel(hDC,cx,cy) << std::endl;
Sleep(5);
}
}
答案 0 :(得分:1)
GetPixel()
函数返回COLORREF
,您可以将其转换为RGB
值,如下所示:
COLORREF color = GetPixel(hdc, x, y);
RGBTRIPLE rgb;
rgb.rgbtRed = GetRValue(color);
rgb.rgbtGreen = GetGValue(color);
rgb.rgbtBlue = GetBValue(color);