How can I Compare Two Images Pixel by Pixel?
Printable View
How can I Compare Two Images Pixel by Pixel?
Private Declare Function GetPixel Lib "gdi32" Alias "GetPixel" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
for X = 1 to picture1.width
for Y = 1 to picture1.height
if GetPixel(picture1.hdc,x,y) = getpixel(picture2.hdc,x,y) then
end if
next
next
The Above Code Is Not Working Properly.
I don't Want to compare two images by its size
I Want to Compare the images to find out that both are identical or not.
Can N E 1 Help Me?
Load one picture into picture1 control and the other into picture2. Then execute the following function. It loops around all pixels and compares the colour between the two pictures.
VB Code:
Private Function AreBothTheSame() As Boolean Dim x As Long, y As Long For x = 1 To picture1.Width For y = 1 To picture1.Height If getpixel(picture1.hDC, x, y) <> getpixel(picture2.hDC, x, y) Then AreBothTheSame = False Exit Function End If Next Next AreBothTheSame = True End Function
What I want is.....
when i click on the command button, the message should be displayed containing the information about whether both the images are identicle or not.
where should i write the above code?
Try using that function in a command button using a MsgBox to return whether it's identical or not. The function is comparing the images pixel by pixel and it works. ;)Quote:
Originally Posted by jalzaaal
Add 2 picture boxes and a button to a form
VB Code:
Option Explicit Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long Private Function AreBothTheSame() As Boolean Dim x As Long, y As Long For x = 1 To Picture1.Width For y = 1 To Picture1.Height If GetPixel(Picture1.hdc, x, y) <> GetPixel(Picture2.hdc, x, y) Then AreBothTheSame = False Exit Function End If Next Next AreBothTheSame = True End Function Private Sub Command1_Click() If AreBothTheSame() = True Then MsgBox "Both pictures are identical" Else MsgBox "Both pictures are different" End If End Sub Private Sub Form_Load() Set Picture1 = LoadPicture("c:\out1.jpg") Set Picture2 = LoadPicture("c:\out2.jpg") End Sub
Ya... The Above Code is working...
You Have solved my Problem
Thank You So Much :wave: