The code below will check to see if the pictures in the two picture box
match.
Start a new project and add two pictures boxes, command button and
a label. Then cut and paste the code below and add two
pictures in the
picture
boxes.
=========================================================================
Option
Explicit
Private Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As
_
Long, ByVal dwCount As Long, lpBits As Any) As Long
Private Sub
Command1_Click()
Label2.Caption = ComparePictures(Picture1, Picture2)
End
Sub
Private Function ComparePictures(ByRef Picture1 As PictureBox, ByRef
_
Picture2 As PictureBox) As Boolean
Dim i As Long
Dim BMPBits1() As
Byte, BuffSize1 As Long
Dim BMPBits2() As Byte, BuffSize2 As
Long
BuffSize1 = CLng(Picture1.ScaleX(Picture1.Image.Width, vbHimetric,
_
vbPixels) * Picture1.ScaleY(Picture1.Image.Height, vbHimetric,
_
vbPixels))
BuffSize2 = CLng(Picture2.ScaleX(Picture2.Image.Width,
vbHimetric, _
vbPixels) * Picture2.ScaleY(Picture2.Image.Height, vbHimetric,
_
vbPixels))
'Pictures aren't even the same size
If BuffSize1
<> BuffSize2 Then Exit Function
ReDim BMPBits1(0 To BuffSize1 -
1)
ReDim BMPBits2(0 To BuffSize2 - 1)
If
GetBitmapBits(Picture1.Image.Handle, BuffSize1, BMPBits1(0)) Then
If
GetBitmapBits(Picture2.Image.Handle, BuffSize2, BMPBits2(0)) Then
For i = 0
To BuffSize1 - 1
If Not BMPBits1(i) = BMPBits2(i) Then Exit Function
Next
i
ComparePictures = True
End If
End If
End Function