• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 274
  • Last Modified:

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
Asked:
PMH4514
  • 3
  • 2
1 Solution
 
AndyAinscowCommented:
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
 
AndyAinscowCommented:
Ignore the bitblt, thats not the correct function for loading a bitmap into a dc.  (I'm overheating here, wheres the ice cream)
0
 
PMH4514Author Commented:
so how would I check that the returned colorref is 0?

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

??
0
 
AndyAinscowCommented:
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
 
PMH4514Author Commented:
yup, got it. thanks!

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now