Click to See Complete Forum and Search --> : Determining if two pictures are identical
Zvonko
Aug 9th, 1999, 03:44 PM
How can I determine if 2 pictures in pictureboxes are identical?
Darkwraith
Jul 16th, 2003, 03:43 PM
Identical as in what? Same file or same picture?
Kasracer
Jul 16th, 2003, 03:54 PM
If you're reading in from a file or comparing what;s in the ram, a checksum would work well me thinks.
Don't ask me how to do it though, :p
Darkwraith
Jul 16th, 2003, 04:01 PM
If you comparing against another picture, I would say to check each pixel in both pictures against each other, and if all are the same, then the pictures are equal.
The complexity of implementing this operation depends on the programming language.
cyborg
Jul 16th, 2003, 05:12 PM
you can load it as a string using
Open Filename For Binary As #1
PicString = Space(LOF(1))
Get #1, , PicString
Close #1
do this for both pictures, then do:
If PicString = PicString2 Then
'The same
Else
'Not the same
End If
this should work is the file is the same format and it should work for _any_ format.
if you want to compare a .bmp with a .tga, for example, you have to load them both in an array and check all pixels or do it the slow way: load them into a picturebox (or another dc) and check them using getpixel.
D.Viddy
Jul 17th, 2003, 06:02 AM
Dim booInvalid
Picture1.Picture = LoadPicture("C:/Image1.jpg") 'Load first image
Picture2.Picture = LoadPicture("C:/Image2.jpg") 'Load second image
Picture1.ScaleMode = 3 'Scale mode set to pixels
Picture2.ScaleMode = 3 'Scale mode set to pixels
'Test the image demensions first
If Picture1.ScaleWidth = Picture2.ScaleWidth and Picture1.ScaleHeight = Picture2.ScaleHeight Then
'Loop through pixel by pixel to see if the pictures match
For X = 0 to Picture1.ScaleWidth
For Y = 0 to Picture1.ScaleHeight
'Check if pixels are equal
If Not GetPixel (Picture1.hDC, X, Y) = GetPixel (Picture2.hDC, X, Y) Then
booInvalid = True 'Set the Invalid flag (Pictures are not equal)
End If
Next
Next
Else
booInvalid = True 'Set the Invalid flag (Pictures are not equal)
End If
'Return response
If booInvalid = True Then
MsgBox "Pictures ARE NOT identical."
Else
MsgBox "Pictures ARE identical.
End If
This will check if two pictures are identical.
-Dylan
Electroman
Jul 17th, 2003, 06:43 AM
Check out this: http://www.vbforums.com/showthread.php?s=&threadid=221345
The method is extremly fast
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.