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();
以上就是本文的全部内容了,希望大家能够喜欢。
如对本文有疑问,
点击进行留言回复!!
相关文章:
-
-
深入了解c# 匿名类型
一、什么叫做匿名类? 匿名类就是没有名字的类。匿名类不能被引用,只能再创建的时候用new语句来声明。二、匿名类的优势以及应用场景; 1、匿名类型提供了一种方...
[阅读全文]
-
-
C# 实现俄罗斯方块(附源码)
概述俄罗斯方块(tetris)是一款由俄罗斯人阿列克谢·帕基特诺夫发明的休闲游戏,帕基特诺夫爱玩拼图,从拼图游戏里得到灵感,设计出了俄罗斯方块。由于上手简单、老...
[阅读全文]
-
浅析c# 接口
接口:是指定一组函数成员而不是实现他们的引用类型。所以只能类喝啊结构来实现接口,在结成该接口的类里面必须要实现接口的所有方法接口的特点:继承于接口的类,必须要实...
[阅读全文]
-
c# 接口使用实例
用接口实现一个简单的物件的入库,出库如定义一个物流类接口,包含物件所属快递公司名称属性,物件单号属性及信息显示方法。通过物件出库类信息和物件入库类信息继承该接口...
[阅读全文]
-
-
-
-
-
网友评论