是否可以在动态创建的位图中使用Response.Write/WriteFile向http响应流写入内容,而无需将图像保存到硬盘中?
MemoryStream
,并将其分配给 Response.OutputStream
,或者直接在保存位图时直接使用 Response.OutputStream
。// Set the correct content type, so browser/client knows what you are sending
Response.ContentType = "image/jpeg";
Response.Clear();
Bitmap bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb);
Graphics g = Graphics.FromImage(bmp);
bmp.Save(Response.OutputStream, ImageFormat.Jpeg);
byte[]
中,您也可以将其直接转储到Response.BinaryWrite(myByteArray);
中,只要您正确设置了内容类型、长度和处理方式(如@arx所述)。是的。请确保正确设置内容类型,它应该可以正常工作。