picturebox load picture three methods and website CAPTCHA capture

  • 2021-01-14 06:27:44
  • OfStack

Type 1 :(This method is stupid)

Hide several pictureboxs on the page that need to change the image on the page, such as picFrom below
Define first where you need to change the image:
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
Then you can change it (for example picTo image to picFrom image)
this.picTo.Image = ((System.Drawing.Image)(resources.GetObject("picFrom.Image")));

The second:

Use the FileStream object, as shown below:
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()

Number 3 (I think is better)

Load the image in the PictureBox control using the Image.FromFile method, and the image file will be locked when you start the application.
The image file remains locked while the application is running. The image file will be locked even if the Image property is set to Nothing at run time.
PictureBox1.Image = Image.FromFile("C:/WINNT/Web/Wallpaper/Fly Away.jpg")


// Default page request
            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();
            // Captcha request
            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();

That's the end of this article, I hope you enjoyed it.


Related articles: