gpt4 book ai didi

c# - 在通用 handler.ashx 中另存为提示 "image name"?

转载 作者:太空狗 更新时间:2023-10-30 00:56:19 25 4
gpt4 key购买 nike

当我使用 Handler.ashx 显示文件夹中的图像然后尝试通过右键单击它来保存图像时,它一直给我“保存类型”asp.net 通用处理程序选项和处理程序名称作为文件名..

Bitmap target = new Bitmap(width, height);
using (Graphics graphics = Graphics.FromImage(target)) {
graphics.CompositingQuality = CompositingQuality.HighSpeed;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.CompositingMode = CompositingMode.SourceCopy;
graphics.DrawImage(photo, 0, 0, width, height);
using (MemoryStream memoryStream = new MemoryStream()) {
target.Save(memoryStream, ImageFormat.Png);
OutputCacheResponse(context, File.GetLastWriteTime(photoPath));
using (FileStream diskCacheStream = new FileStream(cachePath, FileMode.CreateNew))
{
memoryStream.WriteTo(diskCacheStream);
}
memoryStream.WriteTo(context.Response.OutputStream);
}
}

上面是处理程序和

ImageTiff.ImageUrl = "Handler.ashx?p=" + Parameter; 

这是背后的代码。

我需要用图片名称保存它而不是 handler.ashx

最佳答案

您应该在发送数据之前设置 ContentType 和 Content-Disposition HTTP header :

context.Response.ContentType = "image/png";
context.Response.Headers["Content-Disposition"] = "attachment; filename=yourfilename.png";

关于c# - 在通用 handler.ashx 中另存为提示 "image name"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8098865/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com