title: Convert 32-bit Bitmap to 8-bit (both color and grayscale)
body: <p>I have a System.Drawing.Bitmap with <code>PixelFormat</code> of <code>Format32bppRgb</code>.
  I want this image to be converted to a bitmap of 8bit.</p>
  
  <p>The following is the code to convert a 32-bit image to an 8-bit grayscale image:</p>
  
  <pre><code>        public static Bitmap ToGrayscale(Bitmap bmp)
          {
              int rgb;
              System.Drawing.Color c;
  
              for (int y = 0; y &lt; bmp.Height; y++)
                  for (int x = 0; x &lt; bmp.Width; x++)
                  {
                      c = bmp.GetPixel(x, y);
                      rgb = (int)((c.R + c.G + c.B) / 3);
                      bmp.SetPixel(x, y, System.Drawing.Color.FromArgb(rgb, rgb, rgb));
                  }
              return bmp;
          }
  </code></pre>
  
  <p>However, the <code>Bitmap</code> I end up with still has the PixelFormat Property of <code>Format32bppRgb</code>. </p>
  
  <p>Also, </p>
  
  <ul>
  <li>How can I convert a 32-bit color image into an 8-bit color image?</li>
  </ul>
  
  <p>Thanks for any input!</p>
  
  <p><strong>Related.</strong><br>
   - <a href="https://stackoverflow.com/q/32991171/159072">Convert RGB image to RGB 16-bit and 8-bit</a><br>
   - <a href="https://stackoverflow.com/q/1761042/159072">C# - How to convert an Image into an 8-bit color Image?</a><br>
   - <a href="https://stackoverflow.com/q/9010761/159072">C# Convert Bitmap to indexed colour format</a><br>
   - <a href="https://stackoverflow.com/q/6623077/159072">Color Image Quantization in .NET</a><br>
   - <a href="https://stackoverflow.com/q/34557480/159072">quantization (Reduction of colors of image)</a><br>
   - <a href="https://stackoverflow.com/q/21856184/159072">The best way to reduce quantity of colors in bitmap palette</a>   </p>