Results 1 to 7 of 7

Thread: Determining if two pictures are identical

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ilirska Bistrica, Slovenia
    Posts
    242

    Post

    How can I determine if 2 pictures in pictureboxes are identical?

  2. #2
    Fanatic Member
    Join Date
    Jan 2003
    Posts
    1,004
    Identical as in what? Same file or same picture?
    "Can't" and "shouldn't" are two totally separate things.

    All questions should be answered. All answers should be true. That is why I post.

  3. #3
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    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,

  4. #4
    Fanatic Member
    Join Date
    Jan 2003
    Posts
    1,004
    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.
    "Can't" and "shouldn't" are two totally separate things.

    All questions should be answered. All answers should be true. That is why I post.

  5. #5
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    you can load it as a string using
    VB Code:
    1. Open Filename For Binary As #1
    2.         PicString = Space(LOF(1))
    3.         Get #1, , PicString
    4.     Close #1
    do this for both pictures, then do:
    VB Code:
    1. If PicString = PicString2 Then
    2.         'The same
    3.     Else
    4.         'Not the same
    5.     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.
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  6. #6
    Lively Member D.Viddy's Avatar
    Join Date
    May 2003
    Location
    Soldotna, Alaska
    Posts
    108
    VB Code:
    1. Dim booInvalid
    2.  
    3. Picture1.Picture = LoadPicture("C:/Image1.jpg")     'Load first image
    4. Picture2.Picture = LoadPicture("C:/Image2.jpg")     'Load second image
    5.  
    6. Picture1.ScaleMode = 3     'Scale mode set to pixels
    7. Picture2.ScaleMode = 3     'Scale mode set to pixels
    8.  
    9. 'Test the image demensions first
    10. If Picture1.ScaleWidth = Picture2.ScaleWidth and Picture1.ScaleHeight = Picture2.ScaleHeight Then
    11.      'Loop through pixel by pixel to see if the pictures match
    12.      For X = 0 to Picture1.ScaleWidth
    13.           For Y = 0 to Picture1.ScaleHeight
    14.                'Check if pixels are equal
    15.                If Not GetPixel (Picture1.hDC, X, Y) = GetPixel (Picture2.hDC, X, Y) Then
    16.                     booInvalid = True     'Set the Invalid flag (Pictures are not equal)
    17.                End If
    18.           Next
    19.      Next
    20. Else
    21.      booInvalid = True     'Set the Invalid flag (Pictures are not equal)
    22. End If
    23.  
    24. 'Return response
    25. If booInvalid = True Then
    26.      MsgBox "Pictures ARE NOT identical."
    27. Else
    28.      MsgBox "Pictures ARE identical.
    29. End If

    This will check if two pictures are identical.

    -Dylan
    Last edited by D.Viddy; Jul 17th, 2003 at 06:06 AM.

  7. #7
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    Check out this: http://www.vbforums.com/showthread.p...hreadid=221345
    The method is extremly fast
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width