请帮我看一下程序的问题。
这是我写的一段对比两张图片是否相同的代码,如下Dim a() As Byte, b() As Byte
Dim a2 As String
Open "d:\1.bmp" For Binary As #1
ReDim a(LOF(1) - 1)
Get #1, , a
Close #1
Open "d:\2.bmp" For Binary As #1
ReDim b(LOF(1) - 1)
Get #1, , b
Close #1
If StrConv(a, vbUnicode) = StrConv(b, vbUnicode) Then
Shape1.BackStyle = 1
Shape1.BackColor = QBColor(12) '红色
a2 = "0"
Open "d:\1.txt" For Output As #2
Print #2, a2
Close #2
Else
Shape1.BackStyle = 1
Shape1.BackColor = QBColor(10) '绿色
a2 = "1"
Open "d:\1.txt" For Output As #2
Print #2, a2
Close #2
End If
单独运行是完全正常的,但带到定时截屏对比程序中(也就是说每隔x秒钟截一次屏对比一次)就会出错,就算是屏幕上没有任何变化,Shape也会一红一绿的闪,有人说是比较部分有问题,不能把数据转为字符串来比较,而应该进行二进制比较,分别比较每个元素.并修改如下:
Dim i As Long, k As Boolean
k = False
For i = 0 To UBound(b)
If a(i) <> b(i) Then
k = True '找到不同
Exit For
End If
Next i
Shape1.BackStyle = 1
Open "d:\1.txt" For Append As #2
If k Then '不相同
Shape1.BackColor = vbGreen '绿色
Print #2, "1"
Else '相同
Shape1.BackColor = vbRed '红色
Print #2, "0"
End If
Close #2
我菜鸟一个,不知如何将1.bmp,2.bmp带到修改过的程序里去,请帮助我!
又有人说,我的逻辑设计可能有问题,我现在把整个程序挂上,请大家帮我看看,是哪里错了。谢谢!
区域性截屏-2.rar
(4.45 KB)