How to get the array of RGB values for each pixel of the client area of a window
Is there a way to receive the c开发者_如何学Colour values for each pixel in the client area of a window, with gdi?
As noted in comment by @JerryCoffin. Here's a simple example
hDC = GetDC(hwnd);
hBitmap = CreateCompatibleBitmap(hDC, width, height);
hMemDC = CreateCompatibleDC(hDC);
hOld = SelectObject(hMemDC, hBitmap);
BitBlt(hMemDC, 0, 0, width, height, hDC, x, y, SRCCOPY);
// Clean up
DeleteDC(hMemDC);
ReleaseDC(hwnd, hDC);
You should have a bitmap object selected into memory DC for which you can use GetPixel GDI function and then you can also extract the color values using GetRValue()
, GetGValue()
, and GetBValue()
macros.
精彩评论