利用.NET框架下的FromB ase64Strin g和ToB ase64Strin g方法可以很容易地实现图象文件和XML文件的互换。这样可以轻易解决以X ML格式保存图片的问题。代码如下:
攀枝花交通违章查询Publi c Cla ss Fo rm1
Inhe ritsSyste m.Win dows.Forms.Form
#R egion " Wi ndows窗体设计器生成的代码 "
Publ ic Su b New()特斯拉电池日
MyBas e.New()
Initi alize Compo nent()
在 Init ializ eComp onent() 调用之后添加任何初始化
End Sub
窗体重写处置以清理组件列表。
P rotec ted O verlo ads O verri des S ub Di spose(ByVa l dis posin g AsBoole an)
If d ispos ing T hen
If N ot (c ompon entsIs No thing) The n
c ompon ents.Dispo se()
End If
艾玛电动车EndIf
MyBas e.Dis pose(dispo sing)
En d Sub
Wi ndows窗体设计器所必需的
Pr ivate comp onent s AsSyste m.Com ponen tMode l.ICo ntain er
注意:以下过程是W indow s 窗体设计器所必需的
可以使用W indow s 窗体设计器修改此过程。
不要使用代码编辑器修改它。
Fri end W ithEv entsButto n1 As Syst em.Wi ndows.Form s.But ton
Frie nd Wi thEve nts B utton2 AsSyste m.Win dows.Forms.Butt on
Frien d Wit hEven ts Pi cture Box1As Sy stem.Windo ws.Fo rms.P ictur eBoxFri end W ithEv entsButto n3 As Syst em.Wi ndows.Form s.But ton
Frie nd Wi thEve nts L abel1 As S ystem.Wind ows.F orms.Label
Fr iendWithE vents Labe l2 As Syst em.Wi ndows.Form s.Lab el
<Syst em.Di agnos tics.Debug gerSt epThr ough()> Pr ivate SubIniti alize Compo nent() M e.But ton1= New Syst em.Wi ndows.Form s.But ton()
Me.Butt on2 = NewSyste m.Win dows.Forms.Butt on()
Me.Pictu reBox1 = N ew Sy stem.Windo ws.Fo rms.P ictur eBox()
M e.But ton3= New Syst em.Wi ndows.Form s.But ton()
Me.Labe l1 =New S ystem.Wind ows.F orms.Label()
Me.La bel2= New Syst em.Wi ndows.Form s.Lab el()
Me.Suspe ndLay out()
Butt on1
M e.But ton1.Locat ion = NewSyste m.Dra wing.Point(365, 63)
Me.Butto n1.Na me ="Butt on1"
Me.Butto n1.Si ze =New S ystem.Draw ing.S ize(115, 23)
Me.Bu tton1.TabI ndex= 0
Me.B utton1.Tex t = "将图象保存成XML"
Butt on2
M e.But ton2.Locat ion = NewSyste m.Dra wing.Point(365, 98)Me.Butto n2.Na me ="Butt on2"
Me.Butto n2.Si ze =New S ystem.Draw ing.S ize(115, 23) Me.Bu tton2.TabI ndex= 1
Me.B utton2.Tex t = "从XML中得到图象"
Pict ureBo x1
Me.Pict ureBo x1.Lo catio n = N ew Sy stem.Drawi ng.Po int(18, 6) Me.Pict ureBo x1.Na me ="Pict ureBo x1"
Me.P ictur eBox1.Size = Ne w Sys tem.D rawin g.Siz e(320, 460) M e.Pic tureB ox1.T abInd ex =2
M e.Pic tureB ox1.T abSto p = F alse
Butto n3
Me.Butt on3.L ocati on =New S ystem.Draw ing.P oint(365,28) Me.B utton3.Nam e = "Butto n3"
Me.B utton3.Siz e = N ew Sy stem.Drawi ng.Si ze(115, 23) M e.But ton3.TabIn dex = 3
Me.Bu tton3.Text = "浏览图片…"
Labe l1
Me.Labe l1.Lo catio n = N ew Sy stem.Drawi ng.Po int(369, 135) Me.L abel1.Name = "L abel1"
M e.Lab el1.S ize = NewSyste m.Dra wing.Size(105,95)
Me.L abel1.TabI ndex= 4
L abel2
Me.L abel2.Loca tion= New Syst em.Dr awing.Poin t(367, 437) M e.Lab el2.N ame = "Lab el2"
Me.Label2.Siz e = N ew Sy stem.Drawi ng.Si ze(130, 16)
M e.Lab el2.T abInd ex =5
M e.Lab el2.T ext = "【孟宪会之精彩世界】"
F orm1
Me.Au toSca leBas eSize = Ne w Sys tem.D rawin g.Siz e(5,13) Me.C lient Size= New Syst em.Dr awing.Size(500, 480)
Me.Cont rols.AddRa nge(N ew Sy stem.Windo ws.Fo rms.C ontro l() {Me.La bel2, Me.L abel1, Me.Butto n3, M e.Pic tureB ox1,Me.Bu tton2, Me.Butto n1})
Me.Name= "Fo rm1"
Me.Text= "图象文件和XM L格式文件互换例子"
Me.Resu meLay out(F alse)
En d Sub
#E nd Re gion
Pri vateMyFil e AsStrin g = ""
P rivat e MyF ileEx t AsStrin g = ""
P rivat e Sub Butt on2_C lick(ByVal send er As Syst em.Ob ject, ByVa l e A s
Sys tem.E ventA rgs)_
H andle s But ton2.Click
Di m pic As S tring
Di m MyX ml As Syst em.Xm l.Xml Docum ent = NewSyste m.Xml.XmlD ocume nt()MyX ml.Lo ad("c:\MyP hoto.xml")
Di m pic NodeAs Sy stem.Xml.X mlNod e
p icNod e = M yXml.Selec tSing leNod e("/p ic/ph oto")
pi c = p icNod e.Inn erTex t
D im me moryS tream As S ystem.IO.M emory Strea m
m emory Strea m = N ew Sy stem.IO.Me moryS tream(Conv ert.F romBa se64S tring(pic)) M e.Pic tureB ox1.I mage= New Syst em.Dr awing.Bitm ap(me moryS tream)
m emory Strea m.Clo se()
End Sub
Pri vateSub B utton1_Cli ck(By Val s ender As S ystem.Obje ct, B yVale As
Syste m.Eve ntArg s) _
Han dlesButto n1.Cl ick
If M yFile = "" Then
Me ssage Box.S how("请选择一个图片!", "错误",
Mes sageB oxBut tons.OK, M essag eBoxI con.W arnin g)
ExitSub
EndIf
Dim M yImgAs Sy stem.Drawi ng.Im age = MyIm g.Fro mFile(MyFi le)
Dimmemor yStre am As Syst em.IO.Memo ryStr eam = New
Syste m.IO.Memor yStre am()
MyI mg.Sa ve(me moryS tream, Get Image Type(MyFil eExt))
D im b() AsByte
b = memo ryStr eam.G etBuf fer()
Di m pic As S tring = Co nvert.ToBa se64S tring(b)
memo ryStr eam.C lose()
D im My Xml A s Sys tem.X ml.Xm lDocu ment= New Syst em.Xm l.Xml Docum ent() My Xml.L oadXm l("<p ic><n ame>孟宪会</n ame><photo>" +pic +
"</p hoto></pic>")
MyXm l.Sav e("c:\MyPh oto.x ml")
Lab el1.T ext = "文件被保存到了:" + M icros oft.V isual Basic.ChrW(13)+
"c:\MyPh oto.x ml"
EndSub
Priv ate S ub Bu tton3_Clic k(ByV al se nderAs Sy stem.Objec t, By Val e
As S ystem.Even tArgs) _呼和浩特车管所考试中心
Hand les B utton3.Cli ck
Dim o penFi leDia log1As Ne w Ope nFile Dialo g()
open FileD ialog1.Ini tialD irect ory = "c:\"
o penFi leDia log1.Filte r = "PNG(*.png)|*.pn g|Gif(*.gi f)|*.gif|J pg(*.jpg)|*.jpg|所有图象文件(*.*)|*.*"
openF ileDi alog1.Filt erInd ex =2
o penFi leDia log1.Resto reDir ector y = T rue
If o penFi leDia log1.ShowD ialog() =Dialo gResu lt.OK Then
My File= ope nFile Dialo g1.Fi leNam e()
MyFi leExt = My File.Subst ring(MyFil e.Las tInde xOf(".") + 1)
EndIf
End S ub
Publi c Fun ction GetI mageT ype(B yValstr A s Str ing)As
Sy stem.Drawi ng.Im aging.Imag eForm at
Selec t Cas e str.ToLo wer()
Ca se "j pg"
Retu rn Sy stem.Drawi ng.Im aging.Imag eForm at.Jp eg
Case"gif"
Re turnSyste m.Dra wing.Imagi ng.Im ageFo rmat.Gif
Case "tif f"
Retur n Sys tem.D rawin g.Ima ging.Image Forma t.Tif f()
Case "ico n"
Retur n Sys tem.D rawin g.Ima ging.Image Forma t.Ico n
C ase "image/png"
Re turnSyste m.Dra wing.Imagi ng.Im ageFo rmat.Png
Case Else
Re turnSyste m.Dra wing.Imagi ng.Im ageFo rmat.Memor yBmp
End Sele ct
End F uncti on
Priva te Su b For m1_Cl osing(ByVa l sen der A s Obj ect,ByVal e As
Syst em.Co mpone ntMod el.Ca ncelE ventA rgs)_
H andle s MyB ase.C losin g
S ystem.Diag nosti cs.Pr ocess.Star t("IE xploe", "h ttp://xml.sz.lu ohuet/")
EndSub
EndClass
J AVAV工程师权威认证
桓文c cna最新优惠,年底前免费重考吃“软饭”,我骄傲,java专业培训基地
Win dows高级工程师的培训地
北京现代索纳塔报价【就业】先实习后上岗,入职年薪5-10万!中国IT实验室整理佚名2009-4-22 保存本文推荐给好友收藏本页欢迎进入.NET社区论坛,与200万技术人员互动交
流 >>进入
二手标致308cc首先确保电脑已经安装讯雷,打开VS.NET点击菜单:项目->添加引用->COM->添加对Th under Agent 1.0TypeLibra ry的引用。
1.创建讯雷调用对象
Pr ivate Thun derEn g AsNew T HUNDE RAGEN TLib.Agent'创建讯雷调用对象
Thun derEn g.Add Task("下载地址", "另存文件名", "保存目录","任务注释","引用地址","开始模式", "只从原始地址下载","从原始地址下载线程数") '添加下载任务
Thund erEng.Comm itTas ks()'提交下载任务
2.使用讯雷调用对象查询下载任务信息
sFil eSize = Th under Eng.G etTas kInfo(txtU RL.Te xt, "FileS ize")'获取下载文件大小sDown edSiz e = T hunde rEng.GetTa skInf o(txt URL.T ext,"Comp leted Size")'获取已完成大小
sFile Name= Thu nderE ng.Ge tTask Info(txtUR L.Tex t, "F ileNa me")'获取文件名
二、迅雷平台接口函数定义
获得信息
1. B STR G etInf o(BST R pIn foNam e)
功能:获得迅雷或平台相关信息
参数:
参数名含义
pInfo Name信息名称,有如下4种
◆“T hunde rExis ts”:迅雷是否存在
◆“T hunde rRunn ing”:迅雷是否运行
◆“Thund erVer sion”:迅雷版本号
◆“Platf ormVe rsion”:平台版本号
返回值:返回值是字符串与参数pInfo Name有对应关系
参数返回值
“Thund erExi sts”“true”存在,“false”不存在
“Thu nderR unnin g” “t rue”运行中,“fals e”未运行
“Th under Versi on” 迅雷版本号“x.x.x.x”
“Pla tform Versi on” 平台版本号“x.x.x.x”
2.HRESU LT Ge tInfo Struc t(INT pInf o)
功能:获取迅雷或平台相关全部信息
参数:
参数名含义
pInfo其实是T HUNDE R_INF O类型的结构指针,调用前把它转换为INT类型;调用后结构中将填充平台信息,定义如下:
t ypede f str uct _THUND ER_IN FO
发布评论