Solved

how to see if a bitmap is all black?

Posted on 2006-06-15
5
233 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
  • 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 125 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
function returning CString in a regular win32 DLL 8 161
Turn a spreadsheet into a vba executable. 2 78
Folder Comparison 12 53
Host to IP 7 76
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

911 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now