白云岛资源网 Design By www.pvray.com
以下介绍两种方法:
1.利用WebRequest,WebResponse 类
WebRequest wreq=WebRequest.Create("//img.jbzj.com/file_images/article/201205/logo.gif");
HttpWebResponse wresp=(HttpWebResponse)wreq.GetResponse();
Stream s=wresp.GetResponseStream();
System.Drawing.Image img;
img = System.Drawing.Image.FromStream(s);
img.Save("D:\\aa.gif",ImageFormat.Gif); //保存
//下面直接输出
MemoryStream ms=new MemoryStream();
img.Save(ms,ImageFormat.Gif);
img.Dispose();
Response.ClearContent();
Response.ContentType="image/gif";
Response.BinaryWrite(ms.ToArray());
2.利用 WebClient 类
WebClient my=new WebClient();
byte[] mybyte;
mybyte=my.DownloadData("//img.jbzj.com/file_images/article/201205/logo.gif"); MemoryStream ms=new MemoryStream(mybyte);
System.Drawing.Image img;
img = System.Drawing.Image.FromStream(ms);
img.Save("D:\\a.gif",ImageFormat.Gif); //保存
//下面直接输出
Response.ClearContent();
Response.ContentType="image/gif";
Response.BinaryWrite(mybyte);
如果是真实的图片地址直接用
my.DownloadFile("//img.jbzj.com/file_images/article/201205/logo.gif","D:\\a.gif"); //保存
直接可以保存
1.利用WebRequest,WebResponse 类
WebRequest wreq=WebRequest.Create("//img.jbzj.com/file_images/article/201205/logo.gif");
HttpWebResponse wresp=(HttpWebResponse)wreq.GetResponse();
Stream s=wresp.GetResponseStream();
System.Drawing.Image img;
img = System.Drawing.Image.FromStream(s);
img.Save("D:\\aa.gif",ImageFormat.Gif); //保存
//下面直接输出
MemoryStream ms=new MemoryStream();
img.Save(ms,ImageFormat.Gif);
img.Dispose();
Response.ClearContent();
Response.ContentType="image/gif";
Response.BinaryWrite(ms.ToArray());
2.利用 WebClient 类
WebClient my=new WebClient();
byte[] mybyte;
mybyte=my.DownloadData("//img.jbzj.com/file_images/article/201205/logo.gif"); MemoryStream ms=new MemoryStream(mybyte);
System.Drawing.Image img;
img = System.Drawing.Image.FromStream(ms);
img.Save("D:\\a.gif",ImageFormat.Gif); //保存
//下面直接输出
Response.ClearContent();
Response.ContentType="image/gif";
Response.BinaryWrite(mybyte);
如果是真实的图片地址直接用
my.DownloadFile("//img.jbzj.com/file_images/article/201205/logo.gif","D:\\a.gif"); //保存
直接可以保存
白云岛资源网 Design By www.pvray.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
白云岛资源网 Design By www.pvray.com
暂无评论...