c# - Response.WriteFile -- 写出一个字节流

标签 c# asp.net

是否可以使用 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/

相关文章:

asp.net - 日期选择器 JavaScript

c# - @Html.HiddenFor 是从我的 View 中重新发布显示数据的正确方法

c# Bitmap.Save 透明度不保存在 png 中

asp.net - 在 asp.net 中查看状态与隐藏字段

c# - 如何更改连接字符串初始目录

c# - 对 IIS 站点的第一次请求总是产生 500.21 错误

c# - 我是如何解决这个内存泄漏问题的?

c# - ASP.NET - 网站安装 list 中应包含哪些内容?

c# - 使用 WCF 服务和 DataTable 进行序列化/反序列化时停止自动本地化 DateTime

c# 从 ArrayList 获取对象属性