xcrypt
xcrypt

Reputation: 3366

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 colour values for each pixel in the client area of a window, with gdi?

Upvotes: 2

Views: 1398

Answers (1)

cpx
cpx

Reputation: 17557

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.

Upvotes: 1

Related Questions