So, this is what I came up with. Rather than compare the pixels individually, I used a hashing algorithm fed from the contents of the file. It then compares the individual bytes of the returned hash. In my tests, it came back twice as fast as comparing the individual pixels for a gray-scale bitmap image 1152 X 720 and 101KB big.
Here's the code:
(editing because the first time I posted the code everything looked strange. removed comments.)
Public Shared Function CompareTwoImageHashes(ByVal pathToFirstImage As String, ByVal pathToSecondImage As String) As Boolean
Dim firstImage As FileInfo = New FileInfo(pathToFirstImage)
Dim secondImage As FileInfo = New FileInfo(pathToSecondImage)
If Not firstImage.Exists Then
Throw New ArgumentNullException("pathToFirstImage", "The file referenced by the path does not exist!")
End If
If Not secondImage.Exists Then
Throw New ArgumentNullException("pathToSecondImage", "The file referenced by the path does not exist!")
End If
Dim hashingTool As SHA256Managed
Dim imagesMatch As Boolean = True
Try
Using firstImageStream As New FileStream(firstImage.FullName, FileMode.Open)
Using secondImageStream As New FileStream(secondImage.FullName, FileMode.Open)
hashingTool = SHA256Managed.Create()
Dim imageOneHash As Byte() = hashingTool.ComputeHash(firstImageStream)
Dim imageTwoHash As Byte() = hashingTool.ComputeHash(secondImageStream)
hashingTool.Clear()
If (imageOneHash.Length = imageTwoHash.Length) Then
For length As Integer = 0 To (imageOneHash.Length - 1)
If imageOneHash(length) <> imageTwoHash(length) Then
imagesMatch = False
Exit For
End If
Next
CompareTwoImageHashes = imagesMatch
Else
CompareTwoImageHashes = False
End If
End Using
End Using
Catch ex As Exception
Console.WriteLine("Error during compare: {0}", ex.Message)
End Try
End Function