使用http处理程序输出图像

时间:2013-03-29 14:52:47

标签: c# httphandler

我有我的处理程序的以下代码我调试了它,我可以看到我的图像变量b具有我需要的实际图像但是我无法在浏览器中显示它。当我运行它时,我只是在屏幕上获取System.Drawing.Bitmap而不是图像。我不知道如何将其写入浏览器。任何想法都将非常感谢,谢谢。

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://myaddress");
request.Credentials = new NetworkCredential("username", "password");
request.Method = "GET";
request.Accept = "image/jpeg";

HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream s = response.GetResponseStream();
System.Drawing.Image b = System.Drawing.Image.FromStream(s);
context.Response.ContentType = "image/jpeg";
context.Response.Write(b);

1 个答案:

答案 0 :(得分:1)

将其写入输出流:

b.Save(context.Response.OutputStream, ImageFormat.Jpeg);