本文实例讲述了C#远程获取图片文件流的方法。分享给大家供大家参考,具体如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
protected void Page_Load( object sender, EventArgs e)
{
WebRequest myrequest = WebRequest.Create( "http://xxxxx/userface.jpg" );
WebResponse myresponse = myrequest.GetResponse();
Stream imgstream = myresponse.GetResponseStream();
System.Drawing.Image img = System.Drawing.Image.FromStream(imgstream);
//img.Save(Server.MapPath("test.jpg"),System.Drawing.Imaging.ImageFormat.Jpeg);
MemoryStream ms = new MemoryStream();
img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
Response.ClearContent(); //需要输出图象信息 要修改HTTP头
Response.ContentType = "image/gif" ;
Response.BinaryWrite(ms.ToArray());
}
|
希望本文所述对大家C#程序设计有所帮助。