-
ASP. NET download remote picture save to local method, save crawl remote picture
-
2012-05-16 11:25:51 i
'd
- like to
say two favorites
.
-
Two methods are described below:
1. Using the Webrequest,webresponse class
WebRequest wreq=webrequest.create ("Http://up.2cto.com/2012/0516/20120516112717995.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); Save
Direct output below
MemoryStream ms=new MemoryStream ();
Img. Save (ms,imageformat.gif);
Img. Dispose ();
Response.clearcontent ();
Response.contenttype= "Image/gif";
Response.BinaryWrite (Ms. ToArray ());
2. Using the WebClient class
WebClient my=new WebClient ();
Byte[] MyByte;
Mybyte=my. Downloaddata ("Http://up.2cto.com/2012/0516/20120516112717995.gif"); MemoryStream ms=new MemoryStream (MyByte);
System.Drawing.Image img;
IMG = System.Drawing.Image.FromStream (ms);
Img. Save ("D:\\a.gif", imageformat.gif); Save
Direct output below
Response.clearcontent ();
Response.contenttype= "Image/gif";
Response.BinaryWrite (MyByte);
If it's a real picture address, use it directly.
My. DownloadFile ("Http://up.2cto.com/2012/0516/20120516112717995.gif", "d:\\a.gif"); Save
can be saved directly
Asp. NET download remote picture save to local method, save crawl remote picture