I had a function I used a while back to test the pixel colors in a given screen rect, it was something like this pseudo code.
for (int y = t; y <= b; y++){
for (int x = l; x <= r; x++){
color = GetPixel(hdc_, x, y) & 0x00FFFFFF;
if (color == col){
//cout << "+ " << x << " x " << y << " = " << color << endl << flush;
*rx = x;
*ry = y;
return 1;
}
}
I am wanting to update this code to something, well... better, and faster.
But I don't know how to iterate through the array which contains the data I want, in the same manner I prefer, which is (keeping a rectangle in mind) top left to top right, top to bottom.
Here is my latest code...
void GetPixels(int x, int y, int w, int h)
{
HDC hdc = GetDC(NULL);
RECT rect = { x, y, x + w, y + h };
HDC rectDC = CreateCompatibleDC(hdc);
HBITMAP hbmp = CreateCompatibleBitmap(rectDC, w, h);
DeleteObject(SelectObject(rectDC, hbmp));
BitBlt(rectDC, 0, 0, w, h, hdc, x, y, SRCCOPY);
BITMAPINFO BMI;
BMI.bmiHeader.biSize = sizeof(BMI.bmiHeader);
BMI.bmiHeader.biWidth = w;
BMI.bmiHeader.biHeight = h;
BMI.bmiHeader.biPlanes = 1;
BMI.bmiHeader.biBitCount = 32;
BMI.bmiHeader.biCompression = BI_RGB;
RGBQUAD *pPixels = new RGBQUAD[w * h];
GetDIBits(
rectDC,
hbmp,
y,
h,
pPixels,
&BMI,
DIB_RGB_COLORS
);
// here I need to somehow loop through the array of RGBQUAD struct in a rect manner.
//std::cout << pPixels[0] << std::endl;
delete[] pPixels;
}
Thanks for considering my question, I appreciate your time.