The original text is as follows:
Code:
CopyCode The Code is as follows: Response. Clear ();
Response. contenttype = "image/PNG ";
IMG. Save (response. outputstream, chartformat. PNG );
An exception occurred, which is a common error of GDI +. However, if the format is
Code:Copy codeThe Code is as follows: Response. contenttype = "image/JPEG ";
No error will be reported.
Fortunately, I used to change it
Code:Copy codeThe Code is as follows: Response. contenttype = "image/PNG ";
Using (memorystream MS = new memorystream ())
{
IMG. Save (MS, chartformat. PNG );
Response. outputstream. Write (Ms. getbuffer (), 0, (INT) ms. Length );
}
you can enter a PNG image.
This is because the stream response. outputstream cannot be read back, that is, its canseek attribute
is false. When a PNG image is generated, it is not like jpeg. It is not streaming. If it has been written, it is no longer necessary. Instead, it needs to go back
and constantly write structural data. However, the response stream cannot go back to seek, so it cannot be used directly. Change it to a memorystream that can be
seek. convert it into a PNG image and then output it to the response stream.