Ranorex

Control.CompareImage does not work

 
Post new topic   Reply to topic    Ranorex Forum Index -> Bug Reports
View previous topic :: View next topic  
Author Message
chhb_fancy



Joined: 14 Aug 2008
Posts: 12

PostPosted: Mon Aug 18, 2008 3:18 am    Post subject: Control.CompareImage does not work
The following is my code:

Form Calculator = Application.FindFormTitle("calculator", SearchMatchMode.MatchExact,true,5000);

if(Calculator != null){

Calculator.CaptureImage("D:\\RanorexProject\\Test\\test.bmp");
bool bResult = Calculator.CompareImage("D:\\RanorexProject\\Test\\test.bmp");

}

But the result of 'bResult' alreadys returns false.
Is this a bug or haven't I used the function correctly?

I'm using v1.5 trial version on Windows XP SP3.

Any help is appreciated.
Back to top
View user's profile Send private message
Skarlso



Joined: 07 Aug 2008
Posts: 10

PostPosted: Mon Aug 18, 2008 2:37 pm    Post subject:
First:

YOu don't have to use if(Calculator != null){ because ranorex throws an error if the requested windows does not appear in the set time. By you it's 5000 milliseconds.

Second:

I agreed. This indeed does not work.. I tried:

form.CaptureImage();
bool compare = form.CompareImage();

if (compare) {
Logger.Info("Test Passed");
} else {
Logger.Error("Test Failed");
}

This should compare the same images, but it throws an error that they are not identical. I thougth maybe it is the opposite and also tried a sure to fail test. Which failed. So something else is the problem.
Back to top
View user's profile Send private message
chhb_fancy



Joined: 14 Aug 2008
Posts: 12

PostPosted: Tue Aug 19, 2008 2:56 am    Post subject:
Thanks Skarlso for your response.

Is there any solution for this?
Back to top
View user's profile Send private message
Skarlso



Joined: 07 Aug 2008
Posts: 10

PostPosted: Tue Aug 19, 2008 8:58 am    Post subject:
Unfortunatley no... I could not get it to work..
Back to top
View user's profile Send private message
Support Team
Site Admin


Joined: 07 Jul 2006
Posts: 485

PostPosted: Tue Aug 19, 2008 10:25 am    Post subject:
Sorry, there's an error in the documentation of the Control.CaptureImage(string fileName) method. Unlike stated in the documentation of this method, the image format is not(!) determined by the file extension. In fact, the saved image is always encoded as a PNG image.

Unfortunately, the CompareImage and FindImage methods only take BMP images as valid inputs. However, there's a workaround using the Control.CaptureImage() method that returns a Bitmap instance:
Code: click into code to enlarge
// old code
//Calculator.CaptureImage("D:\\RanorexProject\\Test\\test.bmp");

// workaround
Calculator.CaptureImage().Save("D:\\RanorexProject\\Test\\test.bmp",
    System.Drawing.Imaging.ImageFormat.Bmp);


That should fix the CompareImage/FindImage problems on single-display systems. There's another known issue with multiple-display systems that occurs if the control to compare the image to is not located on the primary display. This bug is fixed in the upcoming V1.5.1 release.

Regards,
Alex
Ranorex Support Team
Back to top
View user's profile Send private message Visit poster's website
Skarlso



Joined: 07 Aug 2008
Posts: 10

PostPosted: Tue Aug 19, 2008 10:54 am    Post subject:
Great! That worked!

Thank you very much!
Gergely.
Back to top
View user's profile Send private message
chhb_fancy



Joined: 14 Aug 2008
Posts: 12

PostPosted: Tue Aug 19, 2008 11:08 am    Post subject:
Thanks Alex for your answer.

Now is working. Smile

If I just wanna compare a rectangle of the image, not entire image.

for example:
Entire image rect: (2, 114) - (1261, 970) 1259 x 856
I wanna verify rect: (100, 100) - (200, 200) 100x 100

Is there any method for this? Any help is appreciated.
Back to top
View user's profile Send private message
Skarlso



Joined: 07 Aug 2008
Posts: 10

PostPosted: Tue Aug 19, 2008 1:47 pm    Post subject:
CompareImage supports a parameter called Location which defines the upper left corner of the image to be compared..
And then you can add the Size and the Offset to. This should give you enough coordinates to enter a rectangle you want to compare.
Back to top
View user's profile Send private message
Support Team
Site Admin


Joined: 07 Jul 2006
Posts: 485

PostPosted: Tue Aug 19, 2008 2:07 pm    Post subject:
Well, the CompareImage method supports a Location parameter, however, only for comparing a control with an image on screen.

For comparing a control to an image loaded from a file you should first generate the clipped image. Then use the CompareImage(string imageFileName, Point offset) method to compare that image to the control at a certain offset in the control.

E.g. first make the 100 x 100 image and then call CompareImage("image.bmp", new Point(50, 50)) to compare pixels (50, 50) to (150, 150) of the control to the image.

Regards,
Alex
Ranorex Support Team
Back to top
View user's profile Send private message Visit poster's website
chhb_fancy



Joined: 14 Aug 2008
Posts: 12

PostPosted: Tue Aug 26, 2008 7:08 am    Post subject:
Thanks Alex for your response.

But how to generate the clipped image?

I couldn't find any method to do it. Do you mean that I should use the third-party tool to do so, such as Photoshop?
Back to top
View user's profile Send private message
Support Team
Site Admin


Joined: 07 Jul 2006
Posts: 485

PostPosted: Tue Aug 26, 2008 9:40 am    Post subject:
Well, you could use a 3rd party tool, but .NET works as well. There are dozens of samples on the internet on how to crop an image. The first I found is this one.

Regards,
Alex
Ranorex Support Team
Back to top
View user's profile Send private message Visit poster's website
chhb_fancy



Joined: 14 Aug 2008
Posts: 12

PostPosted: Tue Aug 26, 2008 10:03 am    Post subject:
Thank you very much. Alex Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Ranorex Forum Index -> Bug Reports All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum