title: How can I create a 4-bit PNG with C#?
body: <p>I am trying to create a 4-bit PNG file in C# but my code does not work.</p>
  
  <p>Here is the code:</p>
  
  <pre><code> Bitmap bmp = new Bitmap(200, 50, PixelFormat.Format4bppIndexed);
   string f = bmp.PixelFormat.ToString();
   Graphics gImage = Graphics.FromImage(bmp);
   gImage.FillRectangle(Brushes.Red, 0, 0, bmp.Width - 20, bmp.Height - 20);
   gImage.DrawRectangle(Pens.White, 0, 0, bmp.Width - 20, bmp.Height - 20);
   gImage.DrawString("Test", SystemFonts.DefaultFont, Brushes.White, 5, 8);
   bmp.Save("C:\\buttons_normal1.png",ImageFormat.Png);
  </code></pre>
  
  <p>The code throws an exception at Graphics gImage line due to PixelFormat set to Format4bppIndexed. I saw a solution here suggesting that the final bitmap can be converted to 4-bit, but that code never worked for me. </p>
  
  <p>Any suggestions?</p>