Private Sub btnMatch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMatch.Click
PatternArrayCreator.BmpTempSave()
Dim dir As New DirectoryInfo("C:\Documents and Settings\Owner\My Documents\Pentominos\")
Dim fileArr As FileInfo() = dir.GetFiles("*.bmp")
Dim fiInfo As FileInfo
Me.Cursor = Cursors.WaitCursor
Application.DoEvents()
Dim bm1 As Bitmap = Image.FromFile("C:\bmpt.bmp")
Dim bm2 As Bitmap = Nothing
Dim bm3 As Bitmap = New Bitmap(121, 201)
Dim are_identical As Boolean = True
For Each fiInfo In fileArr
bm2 = Image.FromFile(fiInfo.FullName)
For x As Integer = 0 To bm3.Width - 1
For y As Integer = 0 To bm3.Height - 1
If bm1.GetPixel(x, y).Equals(bm2.GetPixel(x, y)) Then
are_identical = True
Else
are_identical = False
End If
Next
Next
If are_identical = False Then
MsgBox("The images are different.")
Continue For
Else
MsgBox("The images match.")
Exit Sub
End If
Next
Me.Cursor = Cursors.Default
bm1.Dispose()
bm2.Dispose()
End Sub

VulpesRank #55 · 29.2K reputationPosted Sep 17, 2012, 3:00 PM EDT
If bm1.GetPixel(x, y).Equals(bm2.GetPixel(x, y)) Then
I'd try:
If bm1.GetPixel(x, y).ToArgb() = bm2.GetPixel(x, y).ToArgb() Then
See the remarks in the MSDN docs for the Color.Equals() method:
http://msdn.microsoft.com/en-us/library/e03x8ct2(VS.100).aspx
Duane68 reputationPosted Sep 20, 2012, 8:06 AM EDT
VulpesRank #55 · 29.2K reputationPosted Sep 20, 2012, 9:56 AM EDT
Duane68 reputationPosted Sep 20, 2012, 9:09 PM EDT
Duane68 reputationPosted Sep 21, 2012, 7:22 PM EDT
Likewise if I'm wrong about the above and you can explain why, I'd like to hear about it.
VulpesRank #55 · 29.2K reputationPosted Sep 24, 2012, 2:47 PM EDT
I'd certainly have thought that for two images to be regarded as equal, corresponding pixels should have the same value, but you seem to regard this criterion as being too strong.
What then is your criterion for regarding the two images as being the same - that a high percentage of corresponding pixels are equal?
Duane68 reputationPosted Sep 24, 2012, 3:49 PM EDT
VulpesRank #55 · 29.2K reputationPosted Sep 25, 2012, 7:15 AM EDT
When it finds a pixel which doesn't match, it should set are_identical to false, exit the 'y' for loop and then the 'x' for loop.
It should then pop up a messagebox saying that "The images are different" and continue the for each loop by comparing the next image. When it does so, are_identical should be reset to true.
If all the pixels are the same, then are_identical will still be true on exiting the 'y' and 'x' for loops. It should then pop up a messagebox saying that "The Images match" and exit the subroutine altogether. Incidentally, it would be better here to use Exit For so that the cursor is restored and the bitmaps are disposed of (also need to dispose of bmp3) before the Sub ends 'naturally'.
The only thing I can find in the code which could conceivably be suspect is that the 'x' and 'y' for loops are using bmp3's width and height rather than that of bmp1.
Is it possible that the other bitmaps could have a different size to this?
Duane68 reputationPosted Oct 2, 2012, 8:36 PM EDT