I'm grabbing a portion of the screen and scanning through the pixels for a certain color range.
I looked at MSDN's Capturing an Image example and know how to use the functions.
I can get the bits into an array, but I'm not sure how to do it in such a way that I can loop through it as I would an image. A pseudo-example (which I'm sure is way off):
for ( x = 1; x <= Image.Width; x += 3 )
{
for ( y = 1; y <= Image.Height; y += 3 )
{
red = lpPixels[x];
green = lpPixels[x + 1];
blue = lpPixels[x + 2];
}
}
That's basically what I want to do, so if red, blue, and green is a certain color, I'll know what coordinate it's at (x, y) in the image.
I just don't know how to use GetDIBits in such a way, and how to setup the array appropriately to be able to accomplish this.
Apart from the good answers already given, here's an example of how to get a simple array structure to walk on. (You can use e.g. Goz' code for the iteration.)
GetDIBits reference @ MSDN
You have to select
DIB_RGB_COLORS
as flag foruUsage
and set up theBITMAPINFO
structure and theBITMAPINFOHEADER
structure it contains. When you setbiClrUsed
andbiClrImportant
to zero, there is "no" color table, so you can read the pixels of the bitmap you get fromGetDIBits
as a sequence of RGB values. Using32
as bit count (biBitCount
) sets up the data structure according to MSDN:Since a MS
LONG
is exactly 32 bit long (the size of aDWORD
), you do not have to pay attention to padding (as described in the Remarks section).Code: