当前位置: 移动技术网 > IT编程>开发语言>c# > picturebox加载图片的三种方法与网站验证码的抓取

picturebox加载图片的三种方法与网站验证码的抓取

2019年07月18日  | 移动技术网IT编程  | 我要评论

第一种:(此方法比较笨)

在页面上隐藏几个需要改变页面上图片的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();

以上就是本文的全部内容了,希望大家能够喜欢。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网