如何用Response对象输出图像

2024-12-31 16:14:42
推荐回答(3个)
回答1:

比如在ashx文件里:
public void ProcessRequest(HttpContext context) {
context.Response.ContentType = "image/gif";
context.Response.WriteFile(strImagePath);
}

或者
context.Response.ContentType = "image/gif";
context.Response.Clear();
context.Response.BufferOutput = true;
graphics.Save(context.Response.OutputStream, ImageFormat.Jpeg);

回答2:

比如在ashx文件里:
public
void
ProcessRequest(HttpContext
context)
{
context.Response.ContentType
=
"image/gif";
context.Response.WriteFile(strImagePath);
}
或者
context.Response.ContentType
=
"image/gif";
context.Response.Clear();
context.Response.BufferOutput
=
true;
graphics.Save(context.Response.OutputStream,
ImageFormat.Jpeg);

回答3:

其实最好保存路径,然后在img的src中填上