GetDIBits returns a one-dimensional array of values. For a bitmap that is M pixels wide by N pixels high and uses 24-bit color, the first (M * 3) bytes will be the first row of pixels. This may be followed by some padding bytes. It depends on the BITMAPINFOHEADER. Usually, padding is typically used to fill in a width of 4 bytes. Therefore, if your bitmap is 33 pixels wide, there will actually be (36 * 3) bytes per line.
This "pixel plus additive" is called the "step". For RGB bitmaps, you can calculate the step using: stride = (biWidth * (biBitCount / 8) + 3) & ~3 , where biWidth and biBitCount are taken from BITMAPINFOHEADER.
I'm not sure how you want to traverse the array. If you want to go in half in the upper left corner to the right (provided that this bitmap is from top to bottom):
for (row = 0; row < Image.Height; ++row) { int rowBase = row*stride; for (col = 0; col < Image.Width; ++col) { red = lpPixels[rowBase + col];
Jim mischel
source share