How can I determine if 2 pictures in pictureboxes are identical?
Printable View
How can I determine if 2 pictures in pictureboxes are identical?
Identical as in what? Same file or same picture?
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
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.
you can load it as a string using
do this for both pictures, then do:VB Code:
Open Filename For Binary As #1 PicString = Space(LOF(1)) Get #1, , PicString Close #1
VB Code:
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.
VB Code:
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
Check out this: http://www.vbforums.com/showthread.p...hreadid=221345
The method is extremly fast