src/Foundation/Media/Gimela.Media.Imaging/Helpers/ImageHelper.cs
/// <summary>
/// Set pallete of the 8 bpp indexed image to grayscale.
/// </summary>
/// 
/// <param name="image">Image to initialize.</param>
/// 
/// <remarks>The method initializes palette of
/// <see cref="System.Drawing.Imaging.PixelFormat">Format8bppIndexed</see>
/// image with 256 gradients of gray color.</remarks>
/// 
/// <exception cref="UnsupportedImageFormatException">Provided image is not 8 bpp indexed image.</exception>
/// 
Set pallete of the 8 bpp indexed image to grayscale.
Set pallete of the 8 bpp indexed image to grayscale .
public static void SetGrayscalePalette(Bitmap image)
    {
      if (image.PixelFormat != PixelFormat.Format8bppIndexed)
        throw new UnsupportedImageFormatException("Source image is not 8 bpp image.");
      ColorPalette cp = image.Palette;
      for (int i = 0; i < 256; i++)
      {
        cp.Entries[i] = Color.FromArgb(i, i, i);
      }
      image.Palette = cp;
    }
public static void SetGrayscalePalette ( Bitmap image ) { if ( image . PixelFormat != PixelFormat . Format8bppIndexed ) throw new UnsupportedImageFormatException ( " " ) ; ColorPalette cp = image . Palette ; for ( int i = 0 ; i < 256 ; i ++ ) { cp . Entries [ i ] = Color . FromArgb ( i , i , i ) ; } image . Palette = cp ; }
Set pallete of the 8 bpp indexed image to grayscale.
Set pallete of the 8 bpp indexed image to grayscale .
// check pixel format // get palette // init palette // set palette back
Provided image is not 8 bpp indexed image.
Provided image is not 8 bpp indexed image .
image
Bitmap
Image to initialize.
Image to initialize .
remarks
The method initializes palette of

Format8bppIndexed
The method initializes palette of Format8bppIndexed