Solved

how to see if a bitmap is all black?

Posted on 2006-06-15
5
265 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 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

688 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