Class Imaging
- Namespace
- Ranorex
- Assembly
- Ranorex.Core.dll
Provides methods to create screenshots of elements, to search for images, and for image processing.
public class Imaging : MarshalByRefObject
- Inheritance
-
Imaging
- Inherited Members
Constructors
Imaging()
public Imaging()
Properties
UseMultiThreading
Gets a sets a value disabling or enabling multi-threading for Contains(Element, Bitmap) or Find(Element, Bitmap) operations.
True by default.
public static bool UseMultiThreading { get; set; }
Property Value
Remarks
If this is set to false operations related to Contains(Element, Bitmap) or Find(Element, Bitmap) will take longer, if this is set to true
the processor may be fully utilized until the operation finishes and other tasks may take longer.
Methods
CaptureCompressedImage(Adapter)
Captures a compressed image of an adapter.
public static CompressedImage CaptureCompressedImage(Adapter adapter)
Parameters
adapterAdapterThe adapter to capture.
Returns
- CompressedImage
The captured compressed image.
CaptureCompressedImage(Element)
Captures a compressed image of an element.
public static CompressedImage CaptureCompressedImage(Element element)
Parameters
elementElementThe element to capture.
Returns
- CompressedImage
The captured compressed image.
CaptureDesktopImage(Element)
Captures an image of element from the desktop.
public static Bitmap CaptureDesktopImage(Element element)
Parameters
elementElementThe element to capture or
nullto capture the whole desktop.
Returns
- Bitmap
The captured image.
CaptureDesktopImage(Rectangle)
Captures an image region from the desktop.
public static Bitmap CaptureDesktopImage(Rectangle rect)
Parameters
rectRectangleThe region to capture.
Returns
- Bitmap
The captured image region.
CaptureDesktopImageWithSurroundingArea(Element, Point?, Color)
Captures an image of the of the element and its surrounding area from the desktop.
public static Bitmap CaptureDesktopImageWithSurroundingArea(Element element, Point? mousePoint, Color highlightColor)
Parameters
elementElementThe element to capture within its periphery.
mousePointPoint?A point specifying the screen coordinates of the current mouse cursor or
nullin order not to capture the mouse cursor.highlightColorColorThe color used to highlight the element within its surrounding area or Empty to not highlight the element.
Returns
- Bitmap
The captured image.
Exceptions
- ArgumentNullException
elementis anullreference.
CaptureDesktopImagesWithSurroundingArea(Element, Point?, Color, Color, int, out Bitmap)
Captures an image of the of the element and its surrounding area from the desktop, creating two images, with different borders and sizes.
public static Bitmap CaptureDesktopImagesWithSurroundingArea(Element element, Point? mousePoint, Color highlightColor1, Color highlightColor2, int alpha, out Bitmap elemImage)
Parameters
elementElementThe element to capture within its periphery.
mousePointPoint?A point specifying the screen coordinates of the current mouse cursor or
nullin order not to capture the mouse cursor.highlightColor1ColorThe color used to highlight the element within its surrounding area or Empty to not highlight the element.
highlightColor2ColorThe color used to highlight the element within its surrounding area or Empty to not highlight the element, used for elemImage.
alphaintThe alpha value used for blending the non-highlighted area with the background.
elemImageBitmapThe captured image of the element rectangle without surround areas or borders.
Returns
- Bitmap
The captured image.
Exceptions
- ArgumentNullException
elementis anullreference.
CaptureImage(Element)
Captures an image of an element.
public static Bitmap CaptureImage(Element element)
Parameters
elementElementThe element to capture.
Returns
- Bitmap
The captured image.
Remarks
Note that the element must be visible to capture a useful image.
CaptureImage(Element, int, bool)
Captures an image of an element.
public static Bitmap CaptureImage(Element element, int delay, bool ensureVisible)
Parameters
elementElementThe element to capture.
delayintCapture wait delay.
ensureVisibleboolIf true, the element is made visible before any capturing is done.
Returns
- Bitmap
The captured image.
Remarks
Note that the element must be visible to capture a useful image.
CaptureImageAuto(Element)
Captures an image of the element even if it is hidden by other elements. If this does not succeed, the visible portion of the element is captured using a screenshot.
public static Bitmap CaptureImageAuto(Element element)
Parameters
elementElementThe element to capture.
Returns
- Bitmap
The captured image.
CaptureImageAuto(Element, bool)
Captures an image of the element even if it is hidden by other elements. If this does not succeed, the visible portion of the element is captured using a screenshot.
public static Bitmap CaptureImageAuto(Element element, bool ensureVisibleIfNeeded)
Parameters
elementElementThe element to capture.
ensureVisibleIfNeededboolIf capturing the image hidden does not succeed, this value specified if the element should be made visible before capturing the screenshot.
Returns
- Bitmap
The captured image.
CaptureImageHidden(Element)
Captures an image of the element even if it is hidden by other elements.
public static Bitmap CaptureImageHidden(Element element)
Parameters
elementElementThe element to capture.
Returns
- Bitmap
The captured image.
Exceptions
- ArgumentNullException
elementis anullreference.
CaptureImageHidden(IntPtr)
Captures an image of the window even if it is hidden by other windows.
public static Bitmap CaptureImageHidden(IntPtr handle)
Parameters
handleIntPtrThe handle of the window to capture.
Returns
- Bitmap
The captured image or
nullif capturing a hidden image fails.
Remarks
This methods does not consider the UseDesktopImageCapture property.
Compare(Element, Bitmap, FindOptions)
Compares the specified feature with (a screenshot of) the
element and returns whether
their similarity is greater than or equal to the value specified by
options.Similarity.
public static bool Compare(Element element, Bitmap feature, Imaging.FindOptions options)
Parameters
elementElementThe element to make a screenshot of.
featureBitmapThe image to compare the screenshot with.
optionsImaging.FindOptionsThe options for the image comparison. The Preprocessing options are applied to both images, the Clipping rectangle only to the screenshot of the
element. The Similarity defines the minimum similarity the images need to have.
Returns
- bool
Trueif the similarity of the two (preprocessed) images is greater than or equal tooptions.Similarity.
Remarks
False will be returned if the feature and the screenshot of the
element (after clipping using the rectangle value of
options.Clipping) do not have the same size.
Exceptions
- RanorexException
If capturing a screenshot of the element fails.
- ArgumentNullException
If
elementisnull.- ArgumentNullException
If
featureisnull.- ArgumentException
If the bitmap format of the
featurecannot be converted to that of the screenshot of theelement.
Compare(Bitmap, Bitmap)
Compares imageA and imageB and returns their
similarity.
public static double Compare(Bitmap imageA, Bitmap imageB)
Parameters
Returns
- double
The similarity of the two images.
Remarks
A similarity of zero will be returned if the two images do not have the same size. No preprocessing or clipping is done on the specified images.
Exceptions
- ArgumentNullException
If
imageAisnull.- ArgumentNullException
If
imageBisnull.- ArgumentException
If the bitmap format of the
imageBcannot be converted to that of theimageA.
Compare(Bitmap, Bitmap, FindOptions)
Compares image and feature and returns whether
their similarity is greater than or equal to the value specified by
options.Similarity.
public static bool Compare(Bitmap image, Bitmap feature, Imaging.FindOptions options)
Parameters
imageBitmapThe first image.
featureBitmapThe second image.
optionsImaging.FindOptionsThe options for the image comparison. The Preprocessing options are applied to both images, the Clipping rectangle only to
image. The Similarity defines the minimum similarity the images need to have.
Returns
- bool
Trueif the similarity of the two (preprocessed) images is greater than or equal tooptions.Similarity.
Remarks
False will be returned if the two images (after clipping image
using the rectangle value of options.Clipping)
do not have the same size.
Exceptions
- ArgumentNullException
If
imageisnull.- ArgumentNullException
If
featureisnull.- ArgumentException
If the bitmap format of the
featurecannot be converted to that of theimage.
Compare(Bitmap, Bitmap, double)
Compares imageA and imageB and returns whether
their similarity is greater than or equal to similarity.
public static bool Compare(Bitmap imageA, Bitmap imageB, double similarity)
Parameters
imageABitmapThe first image.
imageBBitmapThe second image.
similaritydoubleThe minimum similarity of the two images in order to return
true.
Returns
- bool
Trueif the similarity of the two images is greater than or equal tosimilarity.
Remarks
False will be returned if the two images do not have the same size. If
similarity is smaller than or equal to zero, true is returned.
Exceptions
- ArgumentNullException
If
imageAisnull.- ArgumentNullException
If
imageBisnull.- ArgumentException
If the bitmap format of the
imageBcannot be converted to that of theimageA.
Contains(Element, Bitmap)
Searches for the specified feature in (a screenshot of) the
element
using Default Imaging.FindOptions
and returns whether the feature is found.
public static bool Contains(Element element, Bitmap feature)
Parameters
elementElementThe element to make a screenshot of in which will be searched.
featureBitmapThe image to search for.
Returns
- bool
Trueif thefeatureis found, otherwisefalse.
Exceptions
- RanorexException
If capturing a screenshot of the element fails.
- ArgumentNullException
If
elementisnull.- ArgumentNullException
If
featureisnull.- ArgumentException
If the
featureis greater in size than the screenshot of theelement.- ArgumentException
If the bitmap format of the
featurecannot be converted to that (color image, Format24bppRgb) of the screenshot of theelement.
Contains(Element, Bitmap, FindOptions)
Searches for the specified feature in (a screenshot of) the
element
and returns whether the feature is found.
public static bool Contains(Element element, Bitmap feature, Imaging.FindOptions options)
Parameters
elementElementThe element to make a screenshot of in which will be searched.
featureBitmapThe image to search for.
optionsImaging.FindOptionsA Imaging.FindOptions instance that defines the options for the search.
Returns
- bool
Trueif thefeatureis found, otherwisefalse.
Exceptions
- RanorexException
If capturing a screenshot of the element fails.
- ArgumentNullException
If
elementisnull.- ArgumentNullException
If
featureisnull.- ArgumentException
If the
featureis greater in size than the screenshot of theelement.- ArgumentException
If the bitmap format of the
featurecannot be converted to that (color image, Format24bppRgb) of the screenshot of theelement.
Contains(Bitmap, Bitmap)
Searches for the specified feature in the image
using Default Imaging.FindOptions
and returns whether the feature is found.
public static bool Contains(Bitmap image, Bitmap feature)
Parameters
Returns
- bool
Trueif thefeatureis found, otherwisefalse.
Exceptions
- ArgumentNullException
If
imageisnull.- ArgumentNullException
If
featureisnull.- ArgumentException
If the
featureis greater in size than theimage.- ArgumentException
If the bitmap format of the
featurecannot be converted to that of theimage.
Contains(Bitmap, Bitmap, FindOptions)
Searches for the specified feature in the image
and returns whether the feature is found.
public static bool Contains(Bitmap image, Bitmap feature, Imaging.FindOptions options)
Parameters
imageBitmapThe image to search in.
featureBitmapThe image to search for.
optionsImaging.FindOptionsA Imaging.FindOptions instance that defines the options for the search.
Returns
- bool
Trueif thefeatureis found, otherwisefalse.
Exceptions
- ArgumentNullException
If
imageisnull.- ArgumentNullException
If
featureisnull.- ArgumentException
If the
featureis greater in size than theimage.- ArgumentException
If the bitmap format of the
featurecannot be converted to that of theimage.
Crop(Bitmap, Rectangle)
Crops the given image by the specified rectangle.
public static Bitmap Crop(Bitmap image, Rectangle cropRect)
Parameters
Returns
- Bitmap
The cropped image.
Find(Element, Bitmap)
Searches for the specified feature in (a screenshot of) the
element and returns a list of Imaging.Matches
using Default Imaging.FindOptions.
public static List<Imaging.Match> Find(Element element, Bitmap feature)
Parameters
elementElementThe element to make a screenshot of in which will be searched.
featureBitmapThe image to search for.
Returns
- List<Imaging.Match>
A list of Imaging.Matches found.
Exceptions
- RanorexException
If capturing a screenshot of the element fails.
- ArgumentNullException
If
elementisnull.- ArgumentNullException
If
featureisnull.- ArgumentException
If the
featureis greater in size than the screenshot of theelement.- ArgumentException
If the bitmap format of the
featurecannot be converted to that (color image, Format24bppRgb) of the screenshot of theelement.
Find(Element, Bitmap, FindOptions)
Searches for the specified feature in (a screenshot of) the
element and returns a list of Imaging.Matches.
public static List<Imaging.Match> Find(Element element, Bitmap feature, Imaging.FindOptions options)
Parameters
elementElementThe element to make a screenshot of in which will be searched.
featureBitmapThe image to search for.
optionsImaging.FindOptionsA Imaging.FindOptions instance that defines the options for the search.
Returns
- List<Imaging.Match>
A list of Imaging.Matches found.
Exceptions
- RanorexException
If capturing a screenshot of the element fails.
- ArgumentNullException
If
elementisnull.- ArgumentNullException
If
featureisnull.- ArgumentException
If the
featureis greater in size than the screenshot of theelement.- ArgumentException
If the bitmap format of the
featurecannot be converted to that (color image, Format24bppRgb) of the screenshot of theelement.
Find(Bitmap, Bitmap)
Searches for the specified feature in the image
and returns a list of Imaging.Matches
using Default Imaging.FindOptions.
public static List<Imaging.Match> Find(Bitmap image, Bitmap feature)
Parameters
Returns
- List<Imaging.Match>
A list of Imaging.Matches found.
Exceptions
- ArgumentNullException
If
imageisnull.- ArgumentNullException
If
featureisnull.- ArgumentException
If the
featureis greater in size than theimage.- ArgumentException
If the bitmap format of the
featurecannot be converted to that of theimage.
Find(Bitmap, Bitmap, FindOptions)
Searches for the specified feature in the image
and returns a list of Imaging.Matches.
public static List<Imaging.Match> Find(Bitmap image, Bitmap feature, Imaging.FindOptions options)
Parameters
imageBitmapThe image to search in.
featureBitmapThe image to search for.
optionsImaging.FindOptionsA Imaging.FindOptions instance that defines the options for the search.
Returns
- List<Imaging.Match>
A list of Imaging.Matches found.
Exceptions
- ArgumentNullException
If
imageisnull.- ArgumentNullException
If
featureisnull.- ArgumentException
If the
featureis greater in size than theimage.- ArgumentException
If the bitmap format of the
featurecannot be converted to that of theimage.
FindSingle(Element, Bitmap)
Searches for the specified feature in (a screenshot of) the
element
using Default Imaging.FindOptions.
public static Imaging.Match FindSingle(Element element, Bitmap feature)
Parameters
elementElementThe element to make a screenshot of in which will be searched.
featureBitmapThe image to search for.
Returns
- Imaging.Match
The first or best Imaging.Match found (as specified in the Default options).
Exceptions
- RanorexException
If capturing a screenshot of the element fails.
- ArgumentNullException
If
elementisnull.- ArgumentNullException
If
featureisnull.- ArgumentException
If the
featureis greater in size than the screenshot of theelement.- ArgumentException
If the bitmap format of the
featurecannot be converted to that (color image, Format24bppRgb) of the screenshot of theelement.- ImageNotFoundException
If the
featurecould not be found.
FindSingle(Element, Bitmap, FindOptions)
Searches for the specified feature in (a screenshot of) the
element.
public static Imaging.Match FindSingle(Element element, Bitmap feature, Imaging.FindOptions options)
Parameters
elementElementThe element to make a screenshot of in which will be searched.
featureBitmapThe image to search for.
optionsImaging.FindOptionsA Imaging.FindOptions instance that defines the options for the search.
Returns
- Imaging.Match
The first or best Imaging.Match found (as specified in the
options).
Exceptions
- RanorexException
If capturing a screenshot of the element fails.
- ArgumentNullException
If
elementisnull.- ArgumentNullException
If
featureisnull.- ArgumentException
If the
featureis greater in size than the screenshot of theelement.- ArgumentException
If the bitmap format of the
featurecannot be converted to that (color image, Format24bppRgb) of the screenshot of theelement.- ImageNotFoundException
If the
featurecould not be found.
FindSingle(Bitmap, Bitmap)
Searches for the specified feature in the image
using Default Imaging.FindOptions.
public static Imaging.Match FindSingle(Bitmap image, Bitmap feature)
Parameters
Returns
- Imaging.Match
The first or best Imaging.Match found (as specified in the Default options).
Exceptions
- ArgumentNullException
If
imageisnull.- ArgumentNullException
If
featureisnull.- ArgumentException
If the
featureis greater in size than theimage.- ArgumentException
If the bitmap format of the
featurecannot be converted to that of theimage.- ImageNotFoundException
If the
featurecould not be found.
FindSingle(Bitmap, Bitmap, FindOptions)
Searches for the specified feature in the image.
public static Imaging.Match FindSingle(Bitmap image, Bitmap feature, Imaging.FindOptions options)
Parameters
imageBitmapThe image to search in.
featureBitmapThe image to search for.
optionsImaging.FindOptionsA Imaging.FindOptions instance that defines the options for the search.
Returns
- Imaging.Match
The first or best Imaging.Match found (as specified in the
options).
Exceptions
- ArgumentNullException
If
imageisnull.- ArgumentNullException
If
featureisnull.- ArgumentException
If the
featureis greater in size than theimage.- ArgumentException
If the bitmap format of the
featurecannot be converted to that of theimage.- ImageNotFoundException
If the
featurecould not be found.
Load(string)
Loads a bitmap file.
public static Bitmap Load(string filename)
Parameters
filenamestringThe filename of the bitmap.
Returns
- Bitmap
The loaded bitmap.
Exceptions
- ArgumentException
If a bitmap cannot be loaded from the specified file.
Resize(Bitmap, double)
Resizes the input image.
public static Bitmap Resize(Bitmap input, double factor)
Parameters
Returns
- Bitmap
The resized image.
Exceptions
- ArgumentNullException
If
inputis null.- ArgumentOutOfRangeException
If width or height of the output image are not positive.
Resize(Bitmap, double, double)
Resizes the input image.
public static Bitmap Resize(Bitmap input, double widthFactor, double heightFactor)
Parameters
inputBitmapAn image.
widthFactordoubleThe factor by which the width of the image should be resized.
heightFactordoubleThe factor by which the height of the image should be resized.
Returns
- Bitmap
The resized image.
Exceptions
- ArgumentNullException
If
inputis null.- ArgumentOutOfRangeException
If width or height of the output image are not positive.
Resize(Bitmap, int, int)
Resizes the input image.
public static Bitmap Resize(Bitmap input, int width, int height)
Parameters
inputBitmapAn image.
widthintThe width the image should be resized to.
heightintThe height the image should be resized to.
Returns
- Bitmap
The resized image with the specified
widthandheight.
Exceptions
- ArgumentNullException
If
inputis null.- ArgumentOutOfRangeException
If width or height are not positive.
TryFindSingle(Element, Bitmap, FindOptions, out Match)
Tries to find the specified feature in (a screenshot of) the
element.
public static bool TryFindSingle(Element element, Bitmap feature, Imaging.FindOptions options, out Imaging.Match match)
Parameters
elementElementThe element to make a screenshot of in which will be searched.
featureBitmapThe image to search for.
optionsImaging.FindOptionsA Imaging.FindOptions instance that defines the options for the search.
matchImaging.MatchThe first or best Imaging.Match found (as specified in the
options),nullif the search failed for any reason or no match was found.
Returns
- bool
Trueif a match was found,falseotherwise.
TryFindSingle(Element, Bitmap, out Match)
Tries to find the specified feature in (a screenshot of) the
element
using Default Imaging.FindOptions.
public static bool TryFindSingle(Element element, Bitmap feature, out Imaging.Match match)
Parameters
elementElementThe element to make a screenshot of in which will be searched.
featureBitmapThe image to search for.
matchImaging.MatchThe first or best Imaging.Match found (as specified in the Default options),
nullif the search failed for any reason or no match was found.
Returns
- bool
Trueif a match was found,falseotherwise.
TryFindSingle(Bitmap, Bitmap, FindOptions, out Match)
Tries to find the specified feature in the image.
public static bool TryFindSingle(Bitmap image, Bitmap feature, Imaging.FindOptions options, out Imaging.Match match)
Parameters
imageBitmapThe image to search in.
featureBitmapThe image to search for.
optionsImaging.FindOptionsA Imaging.FindOptions instance that defines the options for the search.
matchImaging.MatchThe first or best Imaging.Match found (as specified in the
options),nullif the search failed for any reason or no match was found.
Returns
- bool
Trueif a match was found,falseotherwise.
TryFindSingle(Bitmap, Bitmap, out Match)
Tries to find the specified feature in the image
using Default Imaging.FindOptions.
public static bool TryFindSingle(Bitmap image, Bitmap feature, out Imaging.Match match)
Parameters
imageBitmapThe image to search in.
featureBitmapThe image to search for.
matchImaging.MatchThe first or best Imaging.Match found (as specified in the Default options),
nullif the search failed for any reason or no match was found.
Returns
- bool
Trueif a match was found,falseotherwise.