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.
Control.CompareImage does not work
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.
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.
-
- Posts: 14
- Joined: Thu Aug 14, 2008 2:09 am
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
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:
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
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: Select all
// old code
//Calculator.CaptureImage("D:\\RanorexProject\\Test\\test.bmp");
// workaround
Calculator.CaptureImage().Save("D:\\RanorexProject\\Test\\test.bmp",
System.Drawing.Imaging.ImageFormat.Bmp);
Regards,
Alex
Ranorex Support Team
-
- Posts: 14
- Joined: Thu Aug 14, 2008 2:09 am
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
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
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
-
- Posts: 14
- Joined: Thu Aug 14, 2008 2:09 am
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact: