2 Attachment(s)
[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:
Dim bolSame As Boolean
bolSame = ImagesSame(PictureBox1, PictureBox2)
MsgBox bolSame
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)?
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.
Re: [VB6] - Compare images the fast way
Is it possible to check percentage that one matches the other ?
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
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
Re: [VB6] - Compare images the fast way
Translated:
Quote:
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.
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 :)
Re: [VB6] - Compare images the fast way