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
DuanePosted Oct 3, 2012, 12:36 AM
VulpesPosted Sep 25, 2012, 11:15 AM
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?
DuanePosted Sep 24, 2012, 7:49 PM
VulpesPosted Sep 24, 2012, 6:47 PM
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?
DuanePosted Sep 21, 2012, 11:22 PM
Likewise if I'm wrong about the above and you can explain why, I'd like to hear about it.
DuanePosted Sep 21, 2012, 1:09 AM
VulpesPosted Sep 20, 2012, 1:56 PM
DuanePosted Sep 20, 2012, 12:06 PM
VulpesPosted Sep 17, 2012, 7:00 PM
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