?
Solved

how to see if a bitmap is all black?

Posted on 2006-06-15
5
Medium Priority
?
268 Views
Last Modified: 2013-11-20
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
Comment
Question by:PMH4514
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 16911692
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
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 16911719
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 Comment

by:PMH4514
ID: 16911918
so how would I check that the returned colorref is 0?

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

??
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 500 total points
ID: 16911969
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 Comment

by:PMH4514
ID: 16912132
yup, got it. thanks!

0

Featured Post

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question