Image Type

Whenever you want to work with images in bot scripts you need the inbuild Image type. Using the Image type images can be loaded into the script engine, manipulated and used in methods.

Table of contents

Loading an image

Usually you want to load an image from an image file provided with your script file. Images can be stored in any common format, but we strongly recommend you to use .png files (an losseless image file format that supports lossless data compression).

The image filepath provided should be stored relative to the script file. Absolute file paths are supported too, but never use them in scripts you want to share with someone else.

Creating an image

Images can also be created providing their Size and optionally a Color. The image will be null (Image.isNull(); will return true) if no color has been provided.

Creating images using this method can be usefull e.g. to compare such images to other images taken using Apis takeScreenshot methods.

Image methods


Image.isNull();

A null image has all parameters set to zero and no allocated data.

Image.hasAlphaChannel();

Returns true if the image has a format that respects the alpha channel, otherwise returns false.

Image.getWidth();

Returns the images width.

Image.getHeight();

Returns the images height.

Image.getSize();

Returns the images Size.

Image.load(filepath);

Loads image data from filepath. Most common image file extensions are supported but .png files are strongly recommended.

Image.save(filepath);

Saves the image to filepath.

Image.fill(color);

Fills the entire image with the given color.

Image.getPixelColor(position);

Returns the color of the pixel at the given position as a Color object.

Image.setPixelColor(position, color);

Alters the pixels color at the given position.

Image.copy(sub_area);

Returns a sub-area of the image as a new Image.

Image.mirrored(horizontally, vertically);

Returns a mirror of the image as a new Image object.

Image.grayed();

Returns the image in grayscale format as a new Image object.

Image.createMaskFromColor(color);

Creates and returns a mask for this image based on the given color value. The returned mask will be a new Image. Pixels having the provided color will be black on the mask image, every other pixel white.

Image.createMaskFromAlpha();

Builds and returns a mask Image from the alpha channel of this image.

Image.isolateColorRange(min_color, max_color, keep_color);

Turns all pixels black which are not in range of min_color and max_color. Pixels in range keep their color if keep_color is true or become white if false. The method calculates the range to isolate using the HSV color space. Thus it’s good practise to instanciate min_color and max_color as HSV colors.

Image.countDifferentPixels(other_image);

Returns the number of pixels different on two images of the same size.

Image.pixelEqualityTo(other_image);

Calculates the percentage of pixels being the same color and position on both images. (Internally this method uses the Image.countDifferentPixels method).