Image comparion without using repository

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
Saha
Posts: 39
Joined: Tue Mar 01, 2011 6:20 pm

Image comparion without using repository

Post by Saha » Tue Mar 29, 2011 4:34 pm

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,

User avatar
slavikf
Posts: 104
Joined: Mon Sep 13, 2010 9:07 pm
Location: Toronto, Canada
Contact:

Re: Image comparion without using repository

Post by slavikf » Tue Mar 29, 2011 6:05 pm

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?

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Image comparion without using repository

Post by Support Team » Tue Mar 29, 2011 6:28 pm

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
.
Image

Saha
Posts: 39
Joined: Tue Mar 01, 2011 6:20 pm

Re: Image comparion without using repository

Post by Saha » Tue Mar 29, 2011 6:39 pm

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,

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Image comparion without using repository

Post by Support Team » Tue Mar 29, 2011 7:50 pm

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
.
Image

User avatar
slavikf
Posts: 104
Joined: Mon Sep 13, 2010 9:07 pm
Location: Toronto, Canada
Contact:

Re: Image comparion without using repository

Post by slavikf » Tue Mar 29, 2011 8:27 pm

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