1

Possible Duplicate:
How can I check the color depth of a Bitmap?

I'm receiving the path of a picture. I would need to know if that picture is in grayScale. How can I do this?

I'm trying to load that path to a Bitmap using this code, but it keeps saying me that the parameter is not valid.

Bitmap myBitmap = new Bitmap(pFilePath);

Can I check if it is in grayScale from a ByteArray? Or is there some way to do it from a Bitmap? How would that be?

Thanks.

Community
  • 1
  • 1
Nick L Scott
  • 712
  • 1
  • 8
  • 21
  • 1
    Are you sure that file is really in the path you're passing? Try `Bitmap image1 = (Bitmap) Image.FromFile(pFilePath);` – Marco Oct 31 '12 at 12:49
  • Here is your answer : [Check if a picture is in grayscale][1] [1]: http://stackoverflow.com/questions/2150504/how-can-i-check-the-color-depth-of-a-bitmap – Ali Vojdanian Oct 31 '12 at 12:50
  • The problem is that I've tried to create a Bitmap from that path, but it throws me an error. – Nick L Scott Oct 31 '12 at 12:53

1 Answers1

0

check this property

image.PixelFormat

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

Dor Cohen
  • 16,769
  • 23
  • 93
  • 161
  • I think it will have `PixelFormat.Format16bppGrayScale` – Nikhil Agrawal Oct 31 '12 at 12:55
  • This solution is wrong because the expected PixelFormat.Format16bppGrayScale will not be returned for grayscale images in 32bpp, here more info: https://stackoverflow.com/questions/36374760/how-to-find-that-all-pixels-in-an-image-are-grey-scale-or-has-r-g-b-equal-value – ElektroStudios Mar 25 '18 at 07:17