Results 1 to 9 of 9

Thread: [VB6] - Compare images the fast way

  1. #1

    Thread Starter
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    [VB6] - Compare images the fast way

    This can take 2 (large) pictures and tell you if they're the same or different much quicker than using GetPixel or other methods.

    This uses the GetDIBits() API function.

    If anyone has suggestions to make it faster than it naturally is than let me know.

    To use the code, just add ModImageCompare.bas to your project and call the ImagesSame() function, like this:

    vb Code:
    1. Dim bolSame As Boolean
    2.  
    3. bolSame = ImagesSame(PictureBox1, PictureBox2)
    4. MsgBox bolSame
    Attached Images Attached Images  
    Attached Files Attached Files

  2. #2
    Junior Member
    Join Date
    Dec 2005
    Posts
    23

    Re: [VB6] - Compare images the fast way

    If you are going to compare them in such a way that they have to be exactly the same ... which this does ... why not just compare the actual files (or a hash of the actual files)?

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: [VB6] - Compare images the fast way

    That is a better idea if it is possible - but in cases where it isn't (like if the pictures are drawn rather than loaded from a file, or if a picture was loaded via properties), this is a good method.

  4. #4
    Banned
    Join Date
    Jul 2014
    Posts
    3

    Re: [VB6] - Compare images the fast way

    Is it possible to check percentage that one matches the other ?

  5. #5
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    Re: [VB6] - Compare images the fast way

    Hi Lukie Luke and welcome to the forums

    Please don't piggyback your questions onto old threads like this. 1. It clutters up the forums and 2. It means you're less likely to recieve an answer. Instead, start your own thread and ask your question as clearly as possible. If you want to reference this thread then just include a hyperlink to it.

    Regards FD
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

  6. #6
    New Member
    Join Date
    Jun 2024
    Posts
    1

    Re: [VB6] - Compare images the fast way

    Bonsoir, je sais que c'est un vieux post mais suite à une grave maladie j'ai du mettre la programmation de côté...
    voilà, mon soucis avec ton exemple est que si je fais une capture d'écran et que charge une image sauvée bien cela ne marche pas pourtant le 2 images sont identiques.
    merci et bonne soirée

  7. #7
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: [VB6] - Compare images the fast way

    Translated:

    Good evening, I know this is an old post but following a serious illness I had to put programming aside...
    There you go, my problem with your example is that if I take a screenshot and load a saved image it doesn't work however the 2 images are identical.
    thank you and good evening
    This forum is in English. While your question is very much relevant to this thread, since it is about the code in the thread, I was tempted to move it to the Classic VB section as a new thread. I didn't, because it's probably better if you asked the thread...and who knows, maybe somebody will revive this? It's the CodeBank, after all, which is about posting working examples, and asking about those examples, so the post is correct. Unfortunately, it's also 17 years too late. It's very likely that the OP has moved on and will never see the question.

    Starting a new thread that references this one is probably the best thing to do. Start it in English, though, even if you go through Google Translate. You spoke so clearly that even with my very poor, and rusty, French, I understood most of what you wrote, so Google will do a good job.
    My usual boring signature: Nothing

  8. #8
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,656

    Re: [VB6] - Compare images the fast way

    The attached program compares pixel by pixel; with two screenshots it's very unlikely that some pixel somewhere on the screen hasn't changed from one screen shot to another. There's *zero* tolerance in this program; if even a single pixel out of the 2,073,600 (for 1920x1080) to 8,294,400 (for 4k 3840x2160) or even more on some screens has changed, it will no longer be identical according to the code posted. Even saved vs unsaved; the algorithm to save it will change some pixels unless you use a lossless format that supports exactly the format its originally captured (or pasted) in.

    Je parle Francais mais pour les autres ici, on devrait utilisier l'Anglais
    Last edited by fafalone; Jun 9th, 2024 at 01:33 AM.

  9. #9

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