The following two methods are described:
1. Use the WebRequest and WebResponse classes
WebRequest wreq = WebRequest. Create ("http://www.bkjia.com/uploadfile/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
// Output directly below
MemoryStream MS = new MemoryStream ();
Img. Save (MS, ImageFormat. Gif );
Img. Dispose ();
Response. ClearContent ();
Response. ContentType = "image/gif ";
Response. BinaryWrite (ms. ToArray ());
2. Use the WebClient class
WebClient my = new WebClient ();
Byte [] mybyte;
Mybyte = my. DownloadData ("http://www.bkjia.com/uploadfile/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
// Output directly below
Response. ClearContent ();
Response. ContentType = "image/gif ";
Response. BinaryWrite (mybyte );
If it is a real image address, use
My. DownloadFile ("http://www.bkjia.com/uploadfile/2012/0516/20120516112717995.gif", "D: \ a.gif"); // save
Saved directly
Excerpt from advancing with the times