Page 1 of 1

Image comparion without using repository

Posted: Tue Mar 29, 2011 4:34 pm
by Saha
Hi,

I am not using ranorex recording to capture my images. I am using spy to capture the screenshot and then save it as a png file.
Now I am running my application I have to make sure this captured image matches with the application page.
How can I do it ? I have tried to use imaging.Contains method, but my image was not found.
Plese help

Thanks,

Re: Image comparion without using repository

Posted: Tue Mar 29, 2011 6:05 pm
by slavikf
Here is code i use:

Code: Select all

Bitmap image = Imaging.Load ("ScreenShot.png");
Validate.ContainsImage (repo.FormOIS_WinStation_11_EyeSca.Element59648Info,
		image.Clone ( new Rectangle (3,3,image.Width-6,image.Height-6),image.PixelFormat),
		Imaging.FindOptions.Default, 
		"Validation: All figures are correctly drawn");
I found, that Spy can add few pixels on the edge, so i use following construct to remove few pixels from the edge:

Code: Select all

image.Clone ( new Rectangle (3,3,image.Width-6,image.Height-6),image.PixelFormat)
But i found, that it doesn't work in 100% cases. I found, that sometimes my code fails, but if i use Ranorex Validation - it will pass. Can someone explain why?

Re: Image comparion without using repository

Posted: Tue Mar 29, 2011 6:28 pm
by Support Team
slavikf wrote:But i found, that it doesn't work in 100% cases. I found, that sometimes my code fails, but if i use Ranorex Validation - it will pass. Can someone explain why?
The only difference is that Ranorex uses its own Ranorex.Imaging.Crop method instead of the Bitmap.Clone method. You might try to replace the call to Clone with Imaging.Crop.

Regards,
Alex
Ranorex Team

Re: Image comparion without using repository

Posted: Tue Mar 29, 2011 6:39 pm
by Saha
Hi slavikf ,

Thanks for your reply, But I am not using repository. What can be used in place of "repo.FormOIS_WinStation_11_EyeSca.Element59648Info.."

Thanks,

Re: Image comparion without using repository

Posted: Tue Mar 29, 2011 7:50 pm
by Support Team
Saha wrote:What can be used in place of "repo.FormOIS_WinStation_11_EyeSca.Element59648Info.."
Any Ranorex element. See the method overloads in the Ranorex Validate class API:
http://www.ranorex.com/Documentation/Ra ... lidate.htm

Regards,
Alex
Ranorex Team

Re: Image comparion without using repository

Posted: Tue Mar 29, 2011 8:27 pm
by slavikf
I can suggest following code:
public static void imagesCompare (Bitmap expected, Bitmap actual, String success, String error) {
			if (Imaging.Compare (expected, actual)==1)
				Report.Success (success);
			else {
				Report.Failure (error);
				Report.LogData (ReportLevel.Error, "Expected", expected);
				Report.LogData (ReportLevel.Error, "Actual", actual);
				}
		}
Bitmap current = Imaging.CaptureImage (repo.FormOIS_WinStation_11_EyeSca.Element59648);
Bitmap image = Imaging.Load ("TC244.png");
imagesCompare (image, current, "TC244: correct image", "TC244: image is incorrect!");
And instead of repo:
Bitmap current = Imaging.CaptureImage (repo.FormOIS_WinStation_11_EyeSca.Element59648);
You can use some like that:
Bitmap current = Imaging.CaptureImage (Element);
And you can generate Element in Runtime. See here for details:
http://www.ranorex.com/Documentation/Ra ... eImage.htm