Results 1 to 8 of 8

Thread: comparision of images pixel by pixel

  1. #1

    Thread Starter
    Member jalzaaal's Avatar
    Join Date
    Feb 2005
    Posts
    63

    comparision of images pixel by pixel

    How can I Compare Two Images Pixel by Pixel?

  2. #2
    Fanatic Member THEROB's Avatar
    Join Date
    Oct 2000
    Location
    I'm cold and there are wolves after me
    Posts
    575

    Re: comparision of 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
    My secretary hopes that I will pay her, her landlord hopes that she will produce some rent, the Electricity Board hopes that he will settle their bill, and so on. I find it a wonderfully optimistic way of life. [Dirk Gently]

  3. #3

    Thread Starter
    Member jalzaaal's Avatar
    Join Date
    Feb 2005
    Posts
    63

    Re: comparision of images pixel by pixel

    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?

  4. #4
    Fanatic Member THEROB's Avatar
    Join Date
    Oct 2000
    Location
    I'm cold and there are wolves after me
    Posts
    575

    Re: comparision of images pixel by pixel

    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:
    1. Private Function AreBothTheSame() As Boolean
    2.     Dim x As Long, y As Long
    3.    
    4.     For x = 1 To picture1.Width
    5.         For y = 1 To picture1.Height
    6.  
    7.             If getpixel(picture1.hDC, x, y) <> getpixel(picture2.hDC, x, y) Then
    8.                 AreBothTheSame = False
    9.                 Exit Function
    10.             End If
    11.  
    12.         Next
    13.  
    14.     Next
    15.     AreBothTheSame = True
    16. End Function
    My secretary hopes that I will pay her, her landlord hopes that she will produce some rent, the Electricity Board hopes that he will settle their bill, and so on. I find it a wonderfully optimistic way of life. [Dirk Gently]

  5. #5

    Thread Starter
    Member jalzaaal's Avatar
    Join Date
    Feb 2005
    Posts
    63

    Unhappy Re: comparision of images pixel by pixel

    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?

  6. #6
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: comparision of images pixel by pixel

    Quote Originally Posted by jalzaaal
    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.

  7. #7
    Fanatic Member THEROB's Avatar
    Join Date
    Oct 2000
    Location
    I'm cold and there are wolves after me
    Posts
    575

    Re: comparision of images pixel by pixel

    Add 2 picture boxes and a button to a form
    VB Code:
    1. Option Explicit
    2. Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
    3.  
    4. Private Function AreBothTheSame() As Boolean
    5.     Dim x As Long, y As Long
    6.    
    7.     For x = 1 To Picture1.Width
    8.         For y = 1 To Picture1.Height
    9.  
    10.             If GetPixel(Picture1.hdc, x, y) <> GetPixel(Picture2.hdc, x, y) Then
    11.                 AreBothTheSame = False
    12.                 Exit Function
    13.             End If
    14.  
    15.         Next
    16.  
    17.     Next
    18.     AreBothTheSame = True
    19. End Function
    20.  
    21. Private Sub Command1_Click()
    22.     If AreBothTheSame() = True Then
    23.         MsgBox "Both pictures are identical"
    24.     Else
    25.         MsgBox "Both pictures are different"
    26.     End If
    27. End Sub
    28.  
    29. Private Sub Form_Load()
    30.     Set Picture1 = LoadPicture("c:\out1.jpg")
    31.     Set Picture2 = LoadPicture("c:\out2.jpg")
    32.    
    33. End Sub
    My secretary hopes that I will pay her, her landlord hopes that she will produce some rent, the Electricity Board hopes that he will settle their bill, and so on. I find it a wonderfully optimistic way of life. [Dirk Gently]

  8. #8

    Thread Starter
    Member jalzaaal's Avatar
    Join Date
    Feb 2005
    Posts
    63

    Smile Re: comparision of images pixel by pixel

    Ya... The Above Code is working...
    You Have solved my Problem
    Thank You So Much

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