Solved

# how to see if a bitmap is all black?

Posted on 2006-06-15
222 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
Question by:PMH4514
• 3
• 2
5 Comments

LVL 44

Expert Comment

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

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

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

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

??
0

LVL 44

Accepted Solution

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

ID: 16912132
yup, got it. thanks!

0

## Join & Write a Comment Already a member? Login.

### Suggested Solutions

Title # Comments Views Activity
Error on moodle after upgrade 3 106
Complete beginner needs help making a cron job 9 104
FizzBuzz challenge 9 73
Path of Workbook 3 45
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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 tutorial demonstrates a quick way of adding group price to multiple Magento products.

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

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

#### Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!