RanorexNetRanorexNet Documentation
CompareImage Method (location, size)
NamespacesRanorexControlCompareImage(Point, Size)
The function compares the image of the control with an other image on the screen. The positions are given in screen coordinates that are relative to the upper-left corner of the screen.
Declaration Syntax
C#Visual BasicVisual C++
public bool CompareImage(
	Point location,
	Size size
)
Public Function CompareImage ( _
	location As Point, _
	size As Size _
) As Boolean
public:
bool CompareImage(
	Point location, 
	Size size
)
Parameters
location (Point)
Upper-left position of the image to compare.
size (Size)
Size of the image to compare.
Return Value
The function returns true, if the the two images are identical, otherwise false.
Remarks
Supported only in RanorexPro.
Examples
The following sample searches the image "TrackBar.bmp" in the ToolStrip and returns the location of the first pixel in the control if the image could be found. The sample uses the CompareImage function to demonstrate how to compare an image loaded from a file with an other image in the control.
CopyC#
Point point;
if (toolStrip.FindImage("TrackBar.bmp", out point) == true)
{
    Point offset = new Point(point.X - toolStrip.Location.X, point.Y - toolStrip.Location.Y);
    Console.WriteLine("ToolStrip Image \"TrackBar.bmp\" found at Location= {0} Offset= {1}", point, offset);
    if (toolStrip.CompareImage("TrackBar.bmp", offset) == true)
        Console.WriteLine("ToolStrip ImageCompare OK");
    Mouse.Move(point);
}
The following example searches and compares the image "MyImage.bmp" in the first subitem of a ListView.
CopyC#
for (int index = 1; index < itemCount; index++)
{
    Point location = listView.GetSubItemLocation(index, 1, false);
    Size size = listView.GetSubItemSize(index, 1, false);
    string imageFileName = "MyImage.bmp";
    Point point;
    if (listView.FindImage(imageFileName, out point, location, size) == true)
    {
        Console.WriteLine("  Image found Index={0} Name={1} {2} {3}", index, listView.GetItemText(index, 0), location, size);
        Point offset = new Point(point.X - listView.Location.X, point.Y - listView.Location.Y);
        if ( listView.CompareImage(imageFileName, offset) == true )
            Console.WriteLine("    Image compare OK");
        Mouse.Click(MouseButtonType.LeftButton, point.X, point.Y);
    }
}

Assembly: RanorexNet (Module: RanorexNet) Version: 1.5.1.4524