Comparing Bitmaps

Ranorex Studio, Spy, Recorder, and Driver.
cnimnicht
Posts: 5
Joined: Fri Jan 30, 2009 12:46 am

Comparing Bitmaps

Post by cnimnicht » Thu Feb 19, 2009 1:41 am

I know this has been asked before, but I was a bit unclear on the solutions.

I have an app that I need to determine whether an area of the screen is green or red. I've noticed that it is mentioned to use CaptureBitmap to get a bitmap of the window, but I am unable to use CaptureBitmap in VS 2008, I'm not sure if it's because I am missing the correct DLL or not, I do get an option to use CaptureCompressedImage, but that is not what I am looking for. My References are

Ranorex.Core
System
System.Core
System.Data
System.Data.DataSetExtensions
System.Drawing
System.Windows.Forms
System.XML
System.XML.Linq

I'd like to do something similar to the following

repo.MainWindow.SubWindow.CaptureImage (RECT,Test.bmp);
if (CompareImages(Test.bmp,Baseline.bmp))
{
Console.WriteLine("Pass");
}
else
{
Console.WriteLine("Fail");
}

I would be very grateful if you could post a code sample. If this doesn't make sense let me know and I will try to clarify more.

Thank you,
Chris Nimnicht

btw, I think this is probably the best testing tool I have ever used and am thoroughly impressed.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Post by Support Team » Thu Feb 19, 2009 2:51 pm

Chris,

Just use the Ranorex.Imaging class:
Bitmap image = Imaging.CaptureImage(element);

The methods provided by the .NET Bitmap class e.g. Clone() for copying portions of the image, Save(), GetPixel(x,y), etc. should do the trick; however if you have large images to compare then GetPixel() is too slow for the task.

We expect to integrate more image-processing functionality in a future version for example fast/fuzzy image comparison, template matching, ..

Regards,
Michael
Ranorex Team