[已解决]如何获取PNG验证码到GUI界面
本帖最后由 yusan523356 于 2012-6-8 21:38 编辑很早以前就在想这个问题,论坛逛遍了也没找到解决办法,倒是找到很多获取非PNG验证码的办法,诶,求高人指点啊,最好有代码,感激不尽啊,注意是获取PNG验证码啊
这是外网地址http://218.87.6.198/
再次感谢4楼和3楼的朋友,你们真的帮我解决了问题。应该是我之前版本太旧吧,更新后可以了,谢谢大家。 下载图片到本地,然后在pic控件显示,手机上的,没法写代码了… 本帖最后由 seniors 于 2012-6-8 09:57 编辑
随便什么类型的,多可以用这方法显示
#include <INet.au3>
#include <GDIPlusex.au3>
#include <Memory.au3>
Opt("GUICloseOnESC", 0)
$yzm = "http://218.87.6.198/portal/bmp2.jsp"
$hGui = GUICreate("验证码", 300, 200)
$Label3 = GUICtrlCreateLabel("验证码:", 14, 90, 50, 17)
$Input3 = GUICtrlCreateInput("", 70, 86, 50, 21)
$Pic1 = GUICtrlCreatePic("", 130, 90, 50, 20)
Global $hPic = GUICtrlGetHandle(-1)
GUISetState(@SW_SHOW)
xsyzm()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
Exit
Case $Pic1
xsyzm()
EndSwitch
WEnd
Func xsyzm()
$bImage = _INetGetSource($yzm, False)
$bData = Binary($bImage)
$Lenght = BinaryLen($bData)
$hData = _MemGlobalAlloc($Lenght, 0x0002)
$pData = _MemGlobalLock($hData)
$tData = DllStructCreate('byte[' & $Lenght & ']', $pData)
DllStructSetData($tData, 1, $bData)
_MemGlobalUnlock($hData)
$pStream = _WinAPI_CreateStreamOnHGlobal($hData)
_GDIPlus_Startup()
$hImage = _GDIPlus_BitmapCreateFromStream($pStream)
$hBitMap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
$Width = _GDIPlus_ImageGetWidth($hImage)
$Height = _GDIPlus_ImageGetHeight($hImage)
_GDIPlus_ImageDispose($hImage)
_MemGlobalFree($hData)
_GDIPlus_Shutdown()
$oldObj = _SendMessage($hPic, 0x0172, 0, $hBitMap)
_WinAPI_DeleteObject($oldObj)
Local $hObj = _SendMessage($hPic, 0x0173)
If $hObj <> $hBitMap Then
_WinAPI_DeleteObject($hBitMap)
EndIf
DllCall('psapi.dll', 'int', 'EmptyWorkingSet', 'hWnd', -1)
EndFunc ;==>xsyzm Global $url = "http://218.87.6.198/portal/bmp2.jsp"
Global $bmp = @TempDir & "\10037.bmp"
GUICreate("PNG TO GUI", 200, 100, -1, -1)
$pic = GUICtrlCreatePic("", 50, 30, 100, 37)
GUICtrlSetCursor(-1, 0)
GUISetState()
_pic()
While 1
$msg = GUIGetMsg()
Switch $msg
Case -3
Exit
Case $pic
_pic()
EndSwitch
WEnd
Func _pic()
InetGet($url, $bmp)
GUICtrlSetImage($pic, $bmp)
EndFunc ;==>_pic
回复 4# haijie1223
你的代码不行也...GUI一片空白 回复 3# seniors
怎么办?版本问题? 你是没有gdiplusex.au3文件,用下面代码吧
#include <INet.au3>
#include <winapiex.au3>
#include <GDIPlus.au3>
#include <Memory.au3>
Opt("GUICloseOnESC", 0)
$yzm = "http://218.87.6.198/portal/bmp2.jsp"
$hGui = GUICreate("验证码", 300, 200)
$Label3 = GUICtrlCreateLabel("验证码:", 14, 90, 50, 17)
$Input3 = GUICtrlCreateInput("", 70, 86, 50, 21)
$Pic1 = GUICtrlCreatePic("", 130, 90, 50, 20)
Global $hPic = GUICtrlGetHandle(-1)
GUISetState(@SW_SHOW)
xsyzm()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
Exit
Case $Pic1
xsyzm()
EndSwitch
WEnd
Func xsyzm()
$bImage = _INetGetSource($yzm, False)
$bData = Binary($bImage)
$Lenght = BinaryLen($bData)
$hData = _MemGlobalAlloc($Lenght, 0x0002)
$pData = _MemGlobalLock($hData)
$tData = DllStructCreate('byte[' & $Lenght & ']', $pData)
DllStructSetData($tData, 1, $bData)
_MemGlobalUnlock($hData)
$pStream = _WinAPI_CreateStreamOnHGlobal($hData)
_GDIPlus_Startup()
$hImage = _GDIPlus_BitmapCreateFromStream($pStream)
$hBitMap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
$Width = _GDIPlus_ImageGetWidth($hImage)
$Height = _GDIPlus_ImageGetHeight($hImage)
_GDIPlus_ImageDispose($hImage)
_MemGlobalFree($hData)
_GDIPlus_Shutdown()
$oldObj = _SendMessage($hPic, 0x0172, 0, $hBitMap)
_WinAPI_DeleteObject($oldObj)
Local $hObj = _SendMessage($hPic, 0x0173)
If $hObj <> $hBitMap Then
_WinAPI_DeleteObject($hBitMap)
EndIf
DllCall('psapi.dll', 'int', 'EmptyWorkingSet', 'hWnd', -1)
EndFunc ;==>xsyzm
Func _GDIPlus_BitmapCreateFromStream($pStream)
Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromStream", "ptr", $pStream, "int*", 0)
If @error Then Return SetError(@error, @extended, 0)
$GDIP_STATUS = $aResult
Return $aResult
EndFunc ;==>_GDIPlus_BitmapCreateFromStream 回复 7# seniors
还是不行,第二行 回复 7# seniors
我去下载gdiplusex.au3和winapiex.au3后,都提示这个,怎么办呢大神? 用我7楼的就行了
原因是这里面二个库有重复申明的常量,你可以手工修改那两个库 回复 10# seniors
改是改好了,也可以运行了,但是,看不到验证码.... PNG 和 bmp 是不一样哦,感谢大家分享 号称'逛遍论坛'的楼主, 把您的AU3版本换个比较新和版本如何?
别在这老叫'不行' '不行'的了! 事实证明, 前面代码都可行! {:face (356):}这个比较难 $yzm后的地址,估计你本来就打不开
页:
[1]
2