picturebox加載圖片的三種辦法與網站驗證碼的抓取。本站提示廣大學習愛好者:(picturebox加載圖片的三種辦法與網站驗證碼的抓取)文章只能為提供參考,不一定能成為您想要的結果。以下是picturebox加載圖片的三種辦法與網站驗證碼的抓取正文
第一種:(此辦法比擬笨)
在頁面上隱蔽幾個須要轉變頁面上圖片的picturebox,好比上面的picFrom
在須要轉變圖片的辦法處先界說:
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
然後便可以轉變了(好比picTo的圖片要轉變成picFrom的圖片)
this.picTo.Image = ((System.Drawing.Image)(resources.GetObject("picFrom.Image")));
第二種:
應用 FileStream 對象,以下所示:
Dim fs As System.IO.FileStream ' Specify a valid picture file path on your computer. fs = New System.IO.FileStream("C:/WINNT/Web/Wallpaper/Fly Away.jpg", IO.FileMode.Open, IO.FileAccess.Read) PictureBox1.Image = System.Drawing.Image.FromStream(fs) fs.Close()
第三種(我以為是比擬好的)
應用 Image.FromFile 辦法在 PictureBox 控件中加載圖片,該圖片文件將在您啟動運用法式時鎖定。
在運用法式運轉時,圖片文件堅持鎖定。 即便在運轉時將 Image 屬性設置為 Nothing,圖片文件仍將鎖定。
PictureBox1.Image = Image.FromFile("C:/WINNT/Web/Wallpaper/Fly Away.jpg")
//默許頁面要求
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(DefaultUrl);
request.Method = "GET";
request.ContentType = "application/x-www-form-urlencoded";
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0.1) Gecko/20100101 Firefox/5.0.1";
request.Accept = "image/webp,*/*;q=0.8";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream stream = response.GetResponseStream();
string WebContent = new StreamReader(stream, System.Text.Encoding.UTF8).ReadToEnd();
//驗證碼要求
request = (HttpWebRequest)WebRequest.Create(CodeUrl);
request.Method = "GET";
request.ContentType = "application/x-www-form-urlencoded";
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0.1) Gecko/20100101 Firefox/5.0.1";
request.Accept = "image/webp,*/*;q=0.8";
request.CookieContainer = lCC;//!Very Important.!!!
response = (HttpWebResponse)request.GetResponse();
response.Cookies = lCC.GetCookies(request.RequestUri);
stream = response.GetResponseStream();
picCode.Image = Image.FromStream(stream);
//stream.Dispose();
以上就是本文的全體內容了,願望年夜家可以或許愛好。