|
-
Jul 28th, 2002, 10:52 PM
#1
Thread Starter
Addicted Member
Compare two Pictures
Can anyone tell me if there is some API or a good method for checking if two pictures (in Picture Boxes) are the same? I already know how to check pixel by pixel, but i was looking for a faster and/or easier way.
-
Jul 29th, 2002, 03:19 AM
#2
Retired VBF Adm1nistrator
Well checking pixel by pixel isn't difficult.
Very easy actually.
And its not all that slow if you're using GetPixel and SetPixel.
Failing that however, you could use SavePicture, and then compare the two files with File I/O
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Jul 29th, 2002, 08:02 AM
#3
Hyperactive Member
i would say save them to binary temp file, open them into a byte array, and then it is very easy. Check to see if their Upper bounds, or higher indexes are the same. If so, go from 0 to the Upper bound using
For Index = 0 to UBOUND(Bitmap1)
If Bitmap1(Index)<>Bitmap2(Index) then NotEqual
Next Index
That should be about the fastest way imaginable.
-
Jul 29th, 2002, 10:13 AM
#4
Thread Starter
Addicted Member
Yeah, im not very good at File I/O. I just understand it a little bit, but ill play with those ideas.
The method i was using now was
for x = 1 to pic1.width
for y = 1 to pic2.height
if pic1.point(x,y) <> pic2.point(x,y) then
msgbox ("they are not equal")
exit sub
next y
next x
msgbox ("they are equal")
-------------------------------
Is GetPixel faster?
-
Jul 29th, 2002, 10:17 AM
#5
PowerPoster
Significantly faster, but file IO would be faster still I should think.
Gentile or Jew,
O you who turn the wheel and look to windward,
Consider Phlebas, who was once handsome and tall as you...
-
Jul 29th, 2002, 10:20 AM
#6
Retired VBF Adm1nistrator
VB Code:
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Function arePicturesEqual(ByVal pBox1 As PictureBox, pBox2 As PictureBox) As Boolean
arePicturesEqual = True: Dim hDc1 As Long, hDc2 As Long
Dim i As Long, j As Long: pBox1.ScaleMode = 3: pBox2.ScaleMode = 3
hDc1 = pBox1.hdc: hDc2 = pBox2.hdc:
For i = 1 To pBox1.ScaleWidth
For j = 1 To pBox2.ScaleHeight
If Not GetPixel(hDc1, i, j) = GetPixel(hDc2, i, j) Then
arePicturesEqual = False
Exit Function
Next
Next
Next
End Function
Pass both pictureboxes to this function as parameters.
I haven't tested it, but it should work
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Jul 30th, 2002, 11:55 PM
#7
Thread Starter
Addicted Member
Very nice, thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|