Civa
Civa

Reputation: 2176

How to identify the image is greyscale image or color image in c#

I have requirement of validating a bulk number of images (jpg, tif, png) in a folder with height attributes. but the validation rules are different for color images and grayscale images.

but My Problem is

How to identify the image is grayscale image or color image in c#?

at least where to start?

Upvotes: 0

Views: 602

Answers (1)

Omar Alshaker
Omar Alshaker

Reputation: 879

bool IsGreyScale(Bitmap YourCurrentBitmap)
{
Color c;
for(int i=0; i < YourCurrentBitmap.Width; i++)
     for(int j=0; j < YourCurrentBitmap.Height; j++)
          {
               c = YourCurrentBitmap.GetPixel(i,j);
               if(!(c.R == c.G == c.B)) return false;
          }
return true;
}

But this method is relatively slow though.

Upvotes: 2

Related Questions