作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
当我使用 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/
我有 json 数据: { "products": [ { "productId" : 0, "productImg" : "../img/product-ph
我是一名优秀的程序员,十分优秀!