Solved

Detecting a blank or empty bmp file

Posted on 2006-11-21
2
547 Views
Last Modified: 2008-03-10
I would like to know if there is a way to detect a blank bmp file.

Through various ways found on internet, I am able to convert a image to grayscale as well as invert the images but I would like to know if there is a way to see this bmp consists black and white color in it.

In other words, if I have a empty bmp. I can invert the image to black. So my output now is all black. If I detect all black in bmp and no white that means it is empty since it has only one color. If it were not empty, it would have white somewhere.

How can I detect this colors (in my case, only black or white) in a bmp file programmatically.

I am using C# and this is all about windows application.

Thank you in advance,
0
Comment
Question by:sovroc81
2 Comments
 
LVL 15

Accepted Solution

by:
ozymandias earned 500 total points
ID: 17991434
When you say "emtpy" I assume you mean every pixel is of the same color, yes ?

bool IsBlank(Bitmap b){
      Color c = b.GetPixel(0,0);
      for (int x = 0; x < b.Width; x++){
            for (int y = 0; y < b.Height; y++){
                  if (c == b.GetPixel(x,y)){
                        return false;
                  }
            }
      }
      return true;
}
0
 

Author Comment

by:sovroc81
ID: 17991847
That is exactly what  I needed.

Thank you for your help in this.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…

791 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