VB6识别验证码可以使用Encode 和 Decode 函数
下面是函数代码
'=======================================================
' 用途:将十六进制转化为二进制
' 输入:Hex(十六进制数)
' 输入数据类型:String
' 输出:HEX_to_BIN(二进制数)
' 输出数据类型:String
' 输入的最大数为2147483647个字符
'*******************************************************************
'<函数:Encode>
'作用:将字符串内容转化为16进制数据编码,其逆过程是Decode
'参数说明:
'strSource 需要转化的原始字符串
Public Function Encode(strEncode As String) As String
Dim i As Long
Dim chrTmp$
Dim ByteLower$, ByteUpper$
Dim strReturn$ '存储转换后的编码
For i = 1 To Len(strEncode)
chrTmp$ = Mid(strEncode, i, 1)
ByteLower$ = Hex$(AscB(MidB$(chrTmp$, 1, 1)))
If Len(ByteLower$) = 1 Then ByteLower$ = "0" & ByteLower$
ByteUpper$ = Hex$(AscB(MidB$(chrTmp$, 2, 1)))
If Len(ByteUpper$) = 1 Then ByteUpper$ = "0" & ByteUpper$
strReturn$ = strReturn$ & ByteUpper$ & ByteLower$
Next
Encode = strReturn$
End Function
'</函数:Encode>
'誉败<函数:Decode>
'作用:将16进制数据编码转化为字符串,是Encode的逆过程
Public Function Decode(strDecode As String) As String
Dim strCode$ '存储转换后的编码陵悄
On Error GoTo ErrProc
If Len(strDecode) Mod 4 <> 0 Then GoTo ErrProc
For i = 1 To Len(strDecode) Step 4
strCode = Mid$(strDecode, i, 4)
chrTmp$ = ChrW("&H" & strCode)
If chrTmp$ = "?" Then If strCode <> "003F" Then GoTo ErrProc
Decode = Decode & chrTmp$
Exit Function
ErrProc:
Decode = strDecode
'DealwithEvents "不能解析的消息:" & strDecode
'==================================================================
将字符转换成VB6可识别的字符(将字符串内容转庆汪颤化为16进制数据)
' Download by http://www.tugaga.com
Private Sub Command1_Click()
Dim ok As Boolean
Dim bm As BITMAP
Dim dot, bRed, bGreen, bBlue, Y As Long
For kuan = 0 To 49: For gao = 0 To 19
a(kuan, gao).dot = 0
a(kuan, gao).tag = 0
Next: Next
GetObject Picture1.Picture.Handle, Len(bm), bm
Picture2.Height = Picture1.Height
Picture2.Width = Picture1.Width
For gao = 0 To bm.bmHeight - 1
For kuan = 0 To bm.bmWidth - 1
dot = GetPixel(Picture1.hdc, kuan, gao)
bRed = Red(dot)
bGreen = Green(dot)
bBlue = Blue(dot)
Y = (9798 * bRed + 19235 * bGreen + 3735 * bBlue) \ 32768
If Y < 128 Then
dot = 1
Else
dot = 0
End If
If kuan < 6 Or kuan > 43 Or gao < 3 Or gao > 17 Then dot = 0
a(kuan, gao).dot = dot
Next kuan
Next gao