源:http://blog.csdn.net/freexploit/
Option Explicit
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal y As Long) As Long
Private Const CF_BITMAP = 2
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Dim phobit(0 To 9, 0 To 9) As Integer '标识位图的像素
Private Sub cmdGetChar_Click()
Dim X As Long
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim mintCurPos As Integer
With Picture2
For k = 0 To 3 '表示有四个字符,
For i = 0 To 9
mintCurPos = InStr(txtPhoBit.Text, "数字" & i & ":") + 4 '数字字符的当前位置
For j = 0 To 9
X = GetPixel(.hdc, k * 10, j) '获得它的像素值
If (X = 15658734 And Mid(txtPhoBit.Text, mintCurPos + j, 1) = "0") _
Or (X <> 15658734 And Mid(txtPhoBit.Text, mintCurPos + j, 1) = "1") Then '判断像素是否相同。
Else '不同则跳出
Exit For
End If
Next j
If j = 10 Then '在此就可以判断当前字符为 i
txtPhoChar.Text = txtPhoChar.Text & i
Exit For
End If
Next i
Next k
End With
End Sub
Private Sub Form_Load()
txtPhoBit.Text = "数字0:0111111110数字1:0100000001数字2:0100000011数字3:0100000010数字4:0000011000数字5:1111100010数字6:0011111110数字7:1100000000数字8:0111011110数字9:0111100000"
If Not URLDownloadToFile(0, "_getcode.asp">http://bbs.china95.net/DV_getcode.asp", App.Path & "\pho.bmp", 0, 0) Then
Picture2.Picture = LoadPicture(App.Path & "\pho.bmp")
Else
MsgBox "保存图片出错!"
End If
End Sub
我分析了一下你的那张图片,发现在空的地方全是RGB(238,238,238)也就是15658734.
并且它的数字排列的非常的工整,也就是说在任何时候出现的相同数字它的像素图都是一样的。并且每数字都占十个像素。到这里的时假我打算比对每它们所有的相素的,也就是每一个数字要比对10*10次。我总觉得这样浪费时间,后来我也发现只要比对每个数字的第一列字即可得到你想要的数字。
所以开始就将10个数字保存在txtphobit中了,如果像素值为15658734,那么就它的字符设为"0",不等于15658734就设为"1"
这个方法只针对这个图片有效(准确率100%),像chinaren那样,就没有用。
|