Asp. NET download remote picture save to local method, save crawl remote picture

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.