src/Foundation/Media/Gimela.Media.Imaging/Helpers/ImageHelper.cs
/// <summary>
/// Check if specified 8 bpp image is grayscale.
/// </summary>
/// 
/// <param name="image">Image to check.</param>
/// 
/// <returns>Returns <b>true</b> if the image is grayscale or <b>false</b> otherwise.</returns>
/// 
/// <remarks>The methods checks if the image is a grayscale image of 256 gradients.
/// The method first examines if the image's pixel format is
/// <see cref="System.Drawing.Imaging.PixelFormat">Format8bppIndexed</see>
/// and then it examines its palette to check if the image is grayscale or not.</remarks>
/// 
Check if specified 8 bpp image is grayscale.
Check if specified 8 bpp image is grayscale .
public static bool IsGrayscale(Bitmap image)
    {
      bool ret = false;
      if (image.PixelFormat == PixelFormat.Format8bppIndexed)
      {
        ret = true;
        ColorPalette cp = image.Palette;
        Color c;
        for (int i = 0; i < 256; i++)
        {
          c = cp.Entries[i];
          if ((c.R != i) || (c.G != i) || (c.B != i))
          {
            ret = false;
            break;
          }
        }
      }
      return ret;
    }
public static bool IsGrayscale ( Bitmap image ) { bool ret = false ; if ( image . PixelFormat == PixelFormat . Format8bppIndexed ) { ret = true ; ColorPalette cp = image . Palette ; Color c ; for ( int i = 0 ; i < 256 ; i ++ ) { c = cp . Entries [ i ] ; if ( ( c . R != i ) || ( c . G != i ) || ( c . B != i ) ) { ret = false ; break ; } } } return ret ; }
Check if specified 8 bpp image is grayscale.
Check if specified 8 bpp image is grayscale .
// check pixel format // check palette // init palette
None
image
Bitmap
Image to check.
Image to check .
remarks
The methods checks if the image is a grayscale image of 256 gradients.
The method first examines if the image's pixel format is
Format8bppIndexed
The methods checks if the image is a grayscale image of 256 gradients . The method first examines if the image ' s pixel format is Format8bppIndexed