Results 1 to 6 of 6
  1. #1

    How to compare two images

    Hi folks,

    Can anybody help me how to compare two images in qtp..

    Thanks in advance

  2. #2

    Re: How to compare two images

    you might be able to perform a bitmap checkpoint - I haven't found this too reliable in the past but it might work fine in your application.

  3. #3

    Re: How to compare two images

    I found checkpoints too unreliable. I have this code in a .DLL which I call (it's C# code) and it works quite fast and nice:

    //************************************************** ***********
    // Function: CompareBitmaps - compares two bitmaps by
    // computing a hash to check if they are equal
    // Arguments: szFile1 = First file to compare
    // szFile2 = Second file to compare
    // Returns: True if they are the same, false if not
    //************************************************** ***********
    public bool CompareBitmaps(string szFile1, string szFile2)
    Boolean bCompare = true;
    Bitmap bmp1 = (Bitmap)Bitmap.FromFile(szFile1);
    Bitmap bmp2 = (Bitmap)Bitmap.FromFile(szFile2);

    //Test to see if we have the same size of image
    if (bmp1.Size != bmp2.Size)
    return false;
    //Convert each image to a byte array
    System.Drawing.ImageConverter ic = new System.Drawing.ImageConverter();
    byte[] btImage1 = new byte[1];
    btImage1 = (byte[])ic.ConvertTo(bmp1, btImage1.GetType());
    byte[] btImage2 = new byte[1];
    btImage2 = (byte[])ic.ConvertTo(bmp2, btImage2.GetType());

    //Compute a hash for each image
    SHA256Managed shaM = new SHA256Managed();
    byte[] hash1 = shaM.ComputeHash(btImage1);
    byte[] hash2 = shaM.ComputeHash(btImage2);

    if (hash1.Length != hash2.Length)
    return false;

    //Compare the hash values
    for (int i = 0; i < hash1.Length; i++)
    if (hash1[i] != hash2[i])
    bCompare = false;
    // Close everything
    return bCompare;

  4. #4

    Re: How to compare two images

    nice code - could you attach the dll?

  5. #5
    SQA Knight
    Join Date
    Jul 1999
    Grand Rapids, MI

    Re: How to compare two images

    No need. Here is a thread that discusses a QTP DLL that does the same thing:


    Two caveats:

    1. As the above thread discusses in some detail, the DLL is not documented nor officially supported by HP/Merc.

    2. This QTP DLL and the code above share the same shortcoming: they do an exact bit for bit comparison, with no "tolerance" settings which are often needed for "robust" comparisions (for example if you have a 10,000 bit image and say 3 bits don't compare do you really want an error logged when a typical user would never notice the difference?)

  6. #6

    Re: How to compare two images

    Unfortunately, I can't post the .dll but producing the c# dll yourself is quite easy. I've developed a whole library of functions that make my experience with QTP much more gratifying than without.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
BetaSoft Inc.
All times are GMT -8. The time now is 06:03 PM.

Copyright BetaSoft Inc.