[ACCEPTED]-How can I check the color depth of a Bitmap?-bit-depth

Accepted answer
Score: 12

Just check this property


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

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

Score: 3

The proper way to check this is:

For JPEG 21 files you should check the appropriate properties 20 using the PropertyItems collection of the Bitmap. This 19 may contain the appropriate EXIF tags to help 18 determine the bit depth. The next step 17 would be to parse the JPEG header and look for the 16 'start of frame' marker and then the number 15 of components in the image.

The final method 14 is to load the JPEG into a Bitmap object 13 and compare the number of pixels with the 12 forumla (width * height * bytes_per_pixel). So 11 if you load the bitmap and number of bytes 10 of actual raw data is equal to (width * height) then 9 you know it's a safe bet that the image 8 has 1 byte per pixel and as such is grayscale.

The 7 last thing you'll want to check is the PixelFormat 6 of the bitmap itself.

For the TIFF file format 5 you should do the same thing using the PropertyItems 4 collection and check the appropriate tag 3 mentioned in the spec. If these fail then 2 do the image byte comparison and finally 1 use the PixelFormat property as a last resort.

More Related questions