是否可以使用 Response.Write/WriteFile 从动态创建的位图中写入 http 响应流而不将图像保存到硬盘?
最佳答案
您可以使用 MemoryStream
并将其分配给 Response.OutputStream
,或者在保存位图时直接使用 Response.OutputStream
。
this 上的文档中有一个示例页面,尽管它只是将位图直接保存到输出流:
// 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);
关于c# - Response.WriteFile -- 写出一个字节流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3763256/