Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check the color depth of a Bitmap?

I'm working on an application that prints a folder of image files, including JPEG and TIFF. The TIFF images are usually Black and White (1bpp).

After loading the image, I want to determine if the image is Color or B&W or Grayscale so I can send the image to the right printer (color printer or black and white printer).

I'm using the Bitmap constructor image = new Bitmap(filename); to load the image.

EDIT: The answer to check the pixel depth is great for B&W. Any ideas on checking if the image is grayscale without iterating through every pixel?

like image 569
Chris Thompson Avatar asked Jan 27 '10 21:01

Chris Thompson


People also ask

How do I find the color depth of an image?

The color depth information appears after the two numbers that display the pixel dimensions of the image. You can also view color depth information on Overview palette by pressing F9, clicking the Info tab, and viewing the Color Depth field. 1 Choose Help  About PaintShop Pro.

What is the colour depth of a bitmap image?

Common colour depths include 8-bit (256 colours) and 24-bit (16 million colours). It's not usually necessary to use more than 24-bit colour, since the human eye is not able to distinguish that many colours, though broader colour depths may be used for archiving or other high quality work.

How do you calculate bit depth?

Simple calculation. Multiply the total number of pixels by the number of 'bits' of colour (usually 24) and divide the result by 8 (because there are 8 'bits' in a 'byte').


1 Answers

Just check this property

image.PixelFormat

It will match one of the values in System.Drawing.Imaging.PixelFormat

Though you would want to send more than just Black & White to the B&W printer, you should also send any gray scales there as well.

like image 110
Neil N Avatar answered Sep 23 '22 04:09

Neil N