• Status: Solved
• Priority: Medium
• Security: Public
• Views: 277

# how to see if a bitmap is all black?

I have an HBITMAP, 250x250, 24bit,  I need a routine that can determine if all the pixels are black. This doesn't have to be particularilly optimized, I only need it to help me debug (I'm getting some all black images, intermittantly, so I want to plug this routine into various places in the "chain" to find out where it's going all black, merely to debug, so quick -n- dirty is fine)

thanks!
0
PMH4514
• 3
• 2
1 Solution

Freelance programmer / ConsultantCommented:
Well black is colour 0 so just put the bitmap into a dc (bitblt) and check every pixel in a big loop.

The GetPixel function retrieves the red, green, blue (RGB) color value of the pixel at the specified coordinates.

COLORREF GetPixel(
HDC hdc,    // handle to DC
int nXPos,  // x-coordinate of pixel
int nYPos   // y-coordinate of pixel
);
Parameters
hdc
[in] Handle to the device context.
nXPos
[in] Specifies the x-coordinate, in logical units, of the pixel to be examined.
nYPos
[in] Specifies the y-coordinate, in logical units, of the pixel to be examined.
0

Freelance programmer / ConsultantCommented:
Ignore the bitblt, thats not the correct function for loading a bitmap into a dc.  (I'm overheating here, wheres the ice cream)
0

Author Commented:
so how would I check that the returned colorref is 0?

if ( GetPixel(hdc, x, y)  == 0)

??
0

Freelance programmer / ConsultantCommented:
bool IsBitmapBlack(...)
{
loop through x
{
loop through y
{
if ( GetPixel(hdc, x, y)  !=  0)
{
//bitmap is NOT all black, no need to continue
return false;
}
}
}
return true;
}
0

Author Commented:
yup, got it. thanks!

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.