gpt4 book ai didi

c# - 使用保存到内存流的图像导出文件

转载 作者:太空宇宙 更新时间:2023-11-03 21:33:47 26 4
gpt4 key购买 nike

我想将图像保存到已存储在内存流中的文件中。

我已将 asp.net 图表保存到内存流中。

stream1 = new MemoryStream();
chart_location_3.SaveImage(stream1, ChartImageFormat.Png);

然后我使用以下代码导出为 jpg。它触发保存以提示并创建文件但图像将无法打开(“这不是有效的位图文件,或者当前不支持其格式”)

System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;

System.Drawing.Image img;

img = System.Drawing.Image.FromStream(stream1);
response.ClearContent();
response.Clear();
Response.ContentType = "image/jpg";
response.AddHeader("Content-Disposition", "attachment; filename= Exported.jpg;");
response.Write(img);
response.Flush();
response.End();

最佳答案

将响应写入更改为:

response.BinaryWrite(stream1.ToArray());

关于c# - 使用保存到内存流的图像导出文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22896409/

26 4 0
文章推荐: c# - 字符串在 shamsi date fa-ir 中未被识别为有效的日期时间
文章推荐: python - 比较两列中以逗号分隔的项目
文章推荐: c# - 将 List 绑定(bind)到 c# wpf 中的组合框