GetDIBits and loop through pixels using X, Y

后端 未结 5 1052
無奈伤痛
無奈伤痛 2020-11-28 15:43

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 t

5条回答
  •  半阙折子戏
    2020-11-28 16:42

    In the link you post you create a 32-bit bitmap so I'll assume you are reading from a 32-bit bitmap (This assumption may be incorrect).

    Therefore changing your loop to the following should work:

    char* pCurrPixel = (char*)lpPixels;
    for ( y = 0; y < Image.Height; y++ )
    {
        for ( x = 0; x < Image.Width; x++ )
        {
            red = pCurrPixel[0];
            green = pCurrPixel[1];
            blue = pCurrPixel[2];
    
            pCurrPixel += 4;
        }
    }
    

    Things to bear in mind:

    1.Arrays are 0 based in C/C++
    2. You were stepping 3 pixels horizontally and vertically each time. Which meant you aren't visiting every pixel.
    3. A bitmap is usually organised such that there are "height" spans of "width" pixels. Therefore you should step through each pixel in a span and then move to the next span.
    4. As already pointed out make sure you aare reading pixels correctly. in 16-bit mode its more complex

提交回复
热议问题