I used ASP to generate a code picture with the JPG format, today want to change it to PNG format, the results appear GDI + General error, check the n-Long data, only to find the solution, to share this solution of netizens deep gratitude
 Response.Clear (); 
 Response.ContentType = "Image/png"; 
 IMG. Save (Response.outputstream, chartformat.png); The 
 unexpectedly appears to be an exception, which is GDI + generic error. But if the format is Response.ContentType = "Image/jpeg"; The 
 will not error. 
 
 
 has been encountered before, changed to 
 Response.ContentType = "Image/png"; 
  using (MemoryStream ms = new MemoryStream ()) 
  {
          Img. Save (MS, Chartformat.png); 
         response.outputstream.write (Ms. GetBuffer (), 0, (int) Ms. Length); 
  } 
 
 To enter a PNG image. 
 This is due to the inability of the Response.outputstream stream to be read backwards, that is, its CanSeek property 
 is false. PNG image generation is not like JPEG, not streaming, has been written to no longer tube, but need to go back to 
 constantly write structure data. But response flow can't go back to seek, so the direct use is not. Change to a MemoryStream that can 
 seek, sir, into a good PNG image, and then output to the response stream.