How to find equal images?

  • Thread starter Thread starter Saber
  • Start date Start date
S

Saber

There are some Images (System.Drawing.Image) with same widths and heights,
I want to find if 2 images are equal.
How can I do it?

The following code always returns false:

If img1.Equals(img2) Then
MsgBox("ok!")
Else
MsgBox("wrong!")
End If
 
The following code always returns false:

yes because you are checking if the 2 pictures are identical not only in
size but also as image , if there is one bit different set it will return
false although you might not see it with the naked eye


but what you want checking the size can you easily do with a custom function

< not behind my dev pc modus so check for typo`s >

private function ImgCheckSameSize(byval ImageA as image , ImageB as image )
as boolean

if (ImageA.Width = ImageB.Width) AndAlso ( ImageA.Height=ImageB.Height)
then
return true
end if
end function

regards

Michel Posseth [MCP]
 
Saber said:
There are some Images (System.Drawing.Image) with same widths and
heights, I want to find if 2 images are equal.
How can I do it?

The following code always returns false:

If img1.Equals(img2) Then
MsgBox("ok!")
Else
MsgBox("wrong!")
End If

See the help for for System.Drawing.Image.Equals - what it's testing for is
if img1 and img2 point to the same object.

If this is some sort of image-matching game (like
http://en.wikipedia.org/wiki/Concentration_(game)) then it will probably
be much better to get the computer to remember which images are the same
instead of comparing them pixel-by-pixel.

Iterating over two images and comparing each value from
System.Drawing.Bitmap.GetPixel could be slow. I suspect there's a quicker
way not using the .net framework. Google could be your friend.

Andrew
 
Michel,
I don't want checking the size, as I said, the size of images are exactly
equal,
and the Equals method of Object *always* returns false even when I get the
images from "one" image file.

I think I've to do Andrew's solution and compare the images pixel by pixel.

Thanks

Michel Posseth said:
The following code always returns false:

yes because you are checking if the 2 pictures are identical not only in
size but also as image , if there is one bit different set it will return
false although you might not see it with the naked eye


but what you want checking the size can you easily do with a custom
function

< not behind my dev pc modus so check for typo`s >

private function ImgCheckSameSize(byval ImageA as image , ImageB as
image ) as boolean

if (ImageA.Width = ImageB.Width) AndAlso ( ImageA.Height=ImageB.Height)
then
return true
end if
end function

regards

Michel Posseth [MCP]



Saber said:
There are some Images (System.Drawing.Image) with same widths and
heights,
I want to find if 2 images are equal.
How can I do it?

The following code always returns false:

If img1.Equals(img2) Then
MsgBox("ok!")
Else
MsgBox("wrong!")
End If
 
Back
Top