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?
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.
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.
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').
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With