title: Convert bitmap from 16bpp to 8bpp in C#
body: <p>I have a Bitmap with 16bpp. I want to convert that image in my ASP.NET side in a 8bpp image.</p>
  
  <p>I tried a lot of options which I found in the internet but nothing works for me.</p>
  
  <p>I also tried that way: <a href="https://stackoverflow.com/questions/6355135/c-sharp-converting-32bpp-image-to-8bpp">C# Converting 32bpp image to 8bpp</a></p>
  
  <p>But if I want to save the file, I get the following error:</p>
  
  <p>Exception Details: System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.</p>
  
  <pre><code>Line 278:                    System.Drawing.Image img2 = Convert(bm_resize);//byteArrayToImage(gray);
  Line 279:                    
  Line 280:                    img2.Save(helper+"grey2.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
  Line 281:                }
  Line 282:
  </code></pre>
  
  <p>Is there any correct way for my problem?</p>
  
  <p>Full Code:</p>
  
  <pre><code>System.Drawing.Image img2 = Convert(bm_resize);
  img2.Save(path+"test.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
  
  
  public static System.Drawing.Image Convert(Bitmap oldbmp)
      {
          using (MemoryStream ms = new MemoryStream())
          {
              oldbmp.Save(ms, ImageFormat.Gif);
              ms.Position = 0;
              return System.Drawing.Image.FromStream(ms);
          }
      }
  </code></pre>