HI.........
I HAVE TO GENERATE A CODE THAT ENABLE TO COMPARE TWO OR MORE IMAGES. BUT I HAVE MANY PROB. TO RUN
IT GIVES LOGICAL ERRORS MEANS NOT GIVING APPROPIATE OUTPUTS
PLZ CHECK IT.
CODE IS :->
Sub Check()
Dim boomismatch As Boolean
Dim x As Integer
Dim y As Integer
boomismatch = False
For y = 1 To Picture1.Height
For x = 1 To Picture1.Width
If Picture1.Point(x, y) = Picture2.Point(x, y) Then
Picture1.PSet (x, y), RGB(255, 0, 0)
boomismatch = True
Exit For
End If
Next x
If boomismatch = True Then
Exit For
End If
Next y
If boomismatch = True Then
MsgBox "not same"
c = 0
Else
MsgBox "same"
MsgBox Picture1.Name
c = 1
Exit Sub
End If
End Sub
PLZ CHECK IT & SEND IT TO ME. ITS REALLY VERY VERY URGENT 2 ME
BYE
If you want to check if the images are identical, then the logic is simple:
1. Compare sizes, if different then they are not the same
2. If same size, then loop through all pixels and compare if they are the same color.
3. If at least 1 pair of pixels is not the same color, then the images are not same.
You can implement some sort of flexibility, for instance, allow 1% of pixels to be different.
If you want to check if the images are identical, then the logic is simple:
1. Compare sizes, if different then they are not the same
2. If same size, then loop through all pixels and compare if they are the same color.
3. If at least 1 pair of pixels is not the same color, then the images are not same.
You can implement some sort of flexibility, for instance, allow 1% of pixels to be different.
i m tring to do this with all things you say into my mind but i cannt get right answer.
plz check my file
& send suggestions to me
First of all you should set the ScaleMode of the Picture boxes to Pixels so you don't have to loop through a lot of twips and check the same pixel more then once. Secondly use the ScaleWidth and ScaleHeight properties instead of the Height and Width. Thirdly I would wrap this into a more generic function:
VB Code:
Public Function IdenticImages(pic1 As PictureBox, pic2 As PictureBox) As Boolean
Dim x As Long
Dim y As Long
pic1.ScaleMode = vbPixels
pic2.ScaleMode = vbPixels
If pic1.ScaleHeight <> pic2.ScaleHeight Or pic1.ScaleWidth <> pic2.ScaleWidth Then
Exit Function
End If
For y = 0 To pic1.ScaleHeight - 1
For x = 1 To pic1.ScaleWidth - 1
If pic1.Point(x, y) <> pic2.Point(x, y) Then
pic1.PSet (x, y), RGB(255, 0, 0)
Exit Function
End If
Next x
Next y
IdenticImages = True
End Sub
Now you can simply call this function from your code instead.
VB Code:
If IdenticImages(Picture1, Picture2) Then
MsgBox "The pictures are the same!"
c = 1
Else
MsgBox "The images are not the same!"
c = 0
End If
Now, using Point and PSet are very slow so this function will be slow when comparing large images. You could speed it up a little by using the GetPixel API function instead of the Point statement, but it will still be pretty slow on large images.