It's old stuff, too.
Recently used
Write it down so you don't forget it later.
To download a picture, first you have a picture address
To have a picture address, you must first put down the page to analyze the URL
Download Web page generally in two ways
1, with System.Net.WebClient
Using system.net;using system.windows.forms;string url = "http://www.cnblogs.com"; string result = Null;try{ WebClient client = new WebClient (); result = client. downloadstring (URL);} catch (Exception ex) { MessageBox.Show (ex. Message);}
2, with System.Net.HttpWebRequest
Using system.net;using system.io;using system.windows.forms;string result = null;string url = "Http://www.cnblogs.com"; WebResponse response = null; StreamReader reader = null;try{ HttpWebRequest request = (HttpWebRequest) webrequest.create (URL); Request. Method = "GET"; Response = Request. GetResponse (); reader = new StreamReader (response. GetResponseStream (), Encoding.UTF8); result = reader. ReadToEnd ();} catch (Exception ex) { MessageBox.Show (ex. Message);} finally{ if (reader! = null) reader. Close (); if (response! = NULL) response. Close ();}
As for how to find the image URL skip, just say download Picture it
In fact, the same as above, there are two ways:
1,webrequest and WebResponse
WebRequest request = WebRequest.Create ("Http://images.cnblogs.com/logo_small.gif"); WebResponse response = Request. GetResponse (); Stream reader = response. GetResponseStream (); FileStream writer = new FileStream ("X:\\pic.jpg", FileMode.OpenOrCreate, FileAccess.Write); byte[] buff = new byte[512]; int c = 0; The number of bytes actually read while (C=reader. Read (buff, 0, buff. Length)) > 0) { writer. Write (buff, 0, c);} Writer. Close (); writer. Dispose (); reader. Close (); reader. Dispose (); response. Close ();
2,webclient
String url = "Http://images.cnblogs.com/logo_small.gif"; string filepath = "X:\\pic.jpg"; WebClient mywebclient = new WebClient (); mywebclient. DownloadFile (URL, filepath);
C # download Web images