how to see if a bitmap is all black?

Posted on 2006-06-15
Medium Priority
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)

Question by:PMH4514
  • 3
  • 2
LVL 45

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.

  HDC hdc,    // handle to DC
  int nXPos,  // x-coordinate of pixel
  int nYPos   // y-coordinate of pixel
[in] Handle to the device context.
[in] Specifies the x-coordinate, in logical units, of the pixel to be examined.
[in] Specifies the y-coordinate, in logical units, of the pixel to be examined.
LVL 45

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)

Author Comment

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

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

LVL 45

Accepted Solution

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;

Author Comment

ID: 16912132
yup, got it. thanks!


Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
How to fix display issue, screen flickering issue when I plug in power cord to the machine. Before I start explaining the solution lets check out once the issue how it looks like after I connect the power cord. most of you also have faced this…
Suggested Courses

607 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