User Tools

Site Tools


en:code:core:image

Image

This object represents an image.

Functions

Image

Constructor function.

Syntax

var myObject = new Image();
var myObject = new Image(otherImage);
var myObject = new Image(filename);
var myObject = new Image(x, y);

Arguments

  1. otherImage - (Image) other Image to copy
  2. filename - (string) a valid image filename

Exceptions

  • (ParameterTypeError) incorrect parameter type
  • (ParameterCountError) incorrect parameter count

Example

Create a empty Image.

var myObject = new Image();

Create a Image representing a copy of otherImage.

var myObject = new Image(otherImage);

takeScreenshot

Take a screenshot of the whole screen or only of window and store the result in a new Image.

Syntax

var myObject = Image.takeScreenshot();
var myObject = Image.takeScreenshot(window);

Arguments

  1. window - (Window) the window to screenshot

Exceptions

  • (InvalidWindowError) invalid window

takeScreenshotUsingScreenIndex

Take a screenshot of one screen and store the result in a new Image. [Added in Actionaz 3.7.0.]

Syntax

var myObject = Image.takeScreenshotUsingScreenIndex(0);

Arguments

  1. screenIndex - (integer) the index of the screen to screenshot

Exceptions

  • (InvalidScreenIndexError) invalid screen index

Methods

clone

Returns a copy of this Image.

Syntax

myObject.clone();

Returns

  • (Image) a copy of this Image

Example

var copyOfMyObject = myObject.clone();

equals

Returns true if this Image and another are referencing the same image.

Syntax

myObject.equals(other);

Arguments

  1. other - (Image) another Image

Returns

  • (bool) true if other is referencing the same image

Example

if(myFirstObject.equals(mySecondObject))
	//Do something

toString

Returns a string representing this Image.

Syntax

myObject.toString();

Returns

  • (string) a string representing this Image

Example

Console.print(myObject.toString());

Notes

This method is automatically called when trying to convert a Image to a string.

setData

Sets the data of this Image.

Syntax

myObject.setData(data);

Arguments

  1. data - (RawData) RawData of the image

Returns

  • (Image) this Image

Exceptions

  • (ImageDataError) invalid image data

Notes

Supported image formats are BMP, GIF, JPG, JPEG, PNG, PBM, PGM, PPM, TIFF, XBM and XPM.

data

Returns the data of this Image as RawData in the BMP format.

Syntax

myObject.data();

Returns

Exceptions

  • (ImageDataError) unable to get the image data

loadFromFile

Loads the Image from a file.

Syntax

myObject.loadFromFile(filename);

Arguments

  1. filename - (string) filename to load

Returns

  • (Image) this Image

Exceptions

  • (LoadImageError) unable to load the image

Notes

Supported image formats are BMP, GIF, JPG, JPEG, PNG, PBM, PGM, PPM, TIFF, XBM and XPM.

saveToFile

Saves the Image to a file.

Syntax

myObject.saveToFile(filename);

Arguments

  1. filename - (string) filename to save to

Returns

  • (Image) this Image

Exceptions

  • (SaveImageError) unable to save the image

Notes

Supported image formats are BMP, JPG, JPEG, PNG, PPM, TIFF, XBM and XPM.

applyFilter

Applies a filter on this Image.

Syntax

myObject.applyFilter(filter);
myObject.applyFilter(filter, options);

Arguments

  1. filter - (Filter) the filter to use
  2. options - (object) filter options
    • filterChannels - (string) the color channel(s) to perform the filtering on. A string consisting of zero or one entity of each of the characters r,g,b,a
    • filterBorderPolicy - (string) used with the convolution filter. Values are "mirror", "extend" or "wrap"
    • convolutionDivisor - (integer) the convolution divisor
    • convolutionBias - (integer) the convolution bias
    • radius - (number) the radius
    • force - (number) the force (use it, Luke!)
    • center - (object) the center
      • x - (integer) the x coordinate
      • y - (integer) the y coordinate

Returns

  • (Image) this Image

Exceptions

  • (ApplyFilterError) unable to apply the filter

pixel

Returns a pixel from this Image.

Syntax

myObject.pixel(x, y);

Arguments

  1. x - (integer) x coordinate of the pixel to return
  2. y - (integer) y coordinate of the pixel to return

Returns

setPixel

Sets a pixel from this Image.

Syntax

myObject.pixel(x, y, color);
myObject.pixel(x, y, colorString);
myObject.pixel(x, y, red, green, blue);

Arguments

  1. x - (integer) x coordinate of the pixel to set
  2. y - (integer) y coordinate of the pixel to set
  3. color - (Color) color of the pixel to set
  4. red - (integer) red value of the color to set
  5. green - (integer) green value of the color to set
  6. blue - (integer) blue value of the color to set

Returns

  • (Image) this Image

mirror

Mirror this Image.

Syntax

myObject.mirror(mirrorOrientation);

Arguments

  1. mirrorOrientation - (MirrorOrientation) mirror orientation

Returns

  • (Image) this Image

setSize

Resizes this Image.

Syntax

myObject.setSize(size);
myObject.setSize(width, height);

Arguments

  1. size - (Size) the new Image size
  2. width - (integer) the new width of this Image
  3. height - (integer) the new height of this Image

Returns

  • (Image) this Image

size

Returns the size of this Image.

Syntax

myObject.size();

Returns

  • (Size) the size of this Image

width

Returns the width of this Image.

Syntax

myObject.width();

Returns

  • (integer) the width of this Image

height

Returns the height of this Image.

Syntax

myObject.height();

Returns

  • (integer) the height of this Image

copy

Returns a copy of this Image or only a part of it.

Syntax

myObject.copy();
myObject.copy(rect);

Arguments

  1. rect - (Rect) the section of this Image to copy

Returns

  • (Image) a new copy of this Image

findSubImage

Searches for another image contained in this one.

Added in Actionaz 3.0.1.

Syntax

myObject.findSubImage(otherImage);
myObject.findSubImage(otherImage, options);

Arguments

  1. otherImage - (Image) the Image to find
  2. options - (object) search options
    • confidenceMinimum - (integer) the minimum confidence percentage, 100 means perfect match (default: 70)
    • downPyramidCount - (integer) the number of pyramids to use. A pyramid is a subdivision of the image used to accelerate the search. Choose 1 here if the searched image is not very different from this image. (default: 2)
    • method - (Method) the search method to use (default: CorrelationCoefficient) [Added in Actionaz 3.7.0.]

Returns

  • (object) the matching point, or null if no matching point can be found
    • position - (Point) the matching image center
    • confidence - (integer) the confidence percentage

Exceptions

  • (FindSubImageError) an error occured while searching for a sub-image
  • (ParameterTypeError) incorrect parameter type

Example

//Searches for an object on the screen
var screenShot = Image.takeScreenshot();
var imageToFind = new Image("object.png");
 
var searchResult = screenShot.findSubImage(imageToFind);
if(searchResult)
    Console.print("Matching image found, position: " + searchResult.position + ", confidence: " + searchResult.confidence);
else
    Console.print("No matching image found.");

findSubImages

Searches for images contained in this one.

Added in Actionaz 3.0.1.

Syntax

myObject.findSubImages(otherImage);
myObject.findSubImages(otherImage, options);

Arguments

  1. otherImage - (Image) the Image to find
  2. options - (object) search options
    • confidenceMinimum - (integer) the minimum confidence percentage, 100 means perfect match (default: 70)
    • downPyramidCount - (integer) the number of pyramids to use. A pyramid is a subdivision of the image used to accelerate the search. Choose 1 here if the searched image is not very different from this image. (default: 2)
    • searchExpansion - (integer) the number of pixels to shift when searching for another matching image (default: 15)
    • maximumMatches - (integer) the maximal number of matches (default: 10)
    • method - (Method) the search method to use (default: CorrelationCoefficient) [Added in Actionaz 3.7.0.]

Returns

  • (array of objects) the matching points, or null if no matching point can be found
    • position - (Point) the matching image center
    • confidence - (integer) the confidence percentage

Exceptions

  • (FindSubImageError) an error occured while searching for a sub-image
  • (ParameterTypeError) incorrect parameter type

Example

//Searches for objects on the screen
var screenShot = Image.takeScreenshot();
var imageToFind = new Image("object.png");
 
var searchResult = screenShot.findSubImages(imageToFind);
if(searchResult)
{
    Console.print("Matching images found\n");
 
    for(var i = 0; i < searchResult.length; ++i)
    {
        Console.print("position: " + searchResult[i].position + ", confidence: " + searchResult[i].confidence + "\n");
    }
}
else
    Console.print("No matching images found.");

findSubImageAsync

Searches for another image contained in this one in asynchronous mode.

Added in Actionaz 3.0.1.

Syntax

myObject.findSubImageAsync(otherImage, callback);
myObject.findSubImageAsync(otherImage, callback, options);

Arguments

  1. otherImage - (Image) the Image to find
  2. callback(object) - (function) the function that will be called when the search ends
    • position - (Point) the matching image center
    • confidence - (integer) the confidence percentage
  3. options - (object) search options
    • confidenceMinimum - (integer) the minimum confidence percentage, 100 means perfect match (default: 70)
    • downPyramidCount - (integer) the number of pyramids to use. A pyramid is a subdivision of the image used to accelerate the search. Choose 1 here if the searched image is not very different from this image. (default: 2)
    • searchExpansion - (integer) the number of pixels to shift when searching for another matching image (default: 15)
    • method - (Method) the search method to use (default: CorrelationCoefficient) [Added in Actionaz 3.7.0.]

Returns

  • (Image) this Image

Exceptions

  • (FindSubImageError) an error occured while searching for a sub-image
  • (ParameterTypeError) incorrect parameter type

Example

//Searches for an object on the screen
var screenShot = Image.takeScreenshot();
var imageToFind = new Image("object.png");
 
screenShot.findSubImageAsync(imageToFind, function(searchResult)
{
    if(searchResult)
        Console.print("Matching image found, position: " + searchResult.position + ", confidence: " + searchResult.confidence);
    else
        Console.print("No matching image found.");
});

findSubImagesAsync

Searches for images contained in this one in asynchronous mode.

Added in Actionaz 3.0.1.

Syntax

myObject.findSubImagesAsync(otherImage, callback);
myObject.findSubImagesAsync(otherImage, callback, options);

Arguments

  1. otherImage - (Image) the Image to find
  2. callback(object) - (function) the function that will be called when the search ends
    • position - (Point) the matching image center
    • confidence - (integer) the confidence percentage
  3. options - (object) search options
    • confidenceMinimum - (integer) the minimum confidence percentage, 100 means perfect match (default: 70)
    • downPyramidCount - (integer) the number of pyramids to use. A pyramid is a subdivision of the image used to accelerate the search. Choose 1 here if the searched image is not very different from this image. (default: 2)
    • searchExpansion - (integer) the number of pixels to shift when searching for another matching image (default: 15)
    • maximumMatches - (integer) the maximal number of matches (default: 10)
    • method - (Method) the search method to use (default: CorrelationCoefficient) [Added in Actionaz 3.7.0.]

Returns

  • (Image) this Image

Exceptions

  • (FindSubImageError) an error occured while searching for a sub-image
  • (ParameterTypeError) incorrect parameter type

Example

//Searches for objects on the screen
var screenShot = Image.takeScreenshot();
var imageToFind = new Image("object.png");
 
screenShot.findSubImagesAsync(imageToFind, function(searchResult)
{
    if(searchResult)
    {
        Console.print("Matching images found\n");
 
        for(var i = 0; i < searchResult.length; ++i)
        {
            Console.print("position: " + searchResult[i].position + ", confidence: " + searchResult[i].confidence + "\n");
        }
    }
    else
        Console.print("No matching images found.");
});

Enumerations

Filter

Image filters.

Values

  1. ConvolutionFilter: the convolution filter
  2. GaussianBlur: a gaussian blur
  3. Defocus: blurs the image
  4. Highlight: highlight the image
  5. Sharpen: sharpens the image
  6. SharpenMore: sharpens the image
  7. SharpenEvenMore: sharpens the image
  8. EdgeDetect: edge detection filter
  9. BigEdge: edge detection filter (thicker edges)
  10. Emboss: embosses the image (no color preservation)
  11. EmbossColor: embosses the image (color preservation)
  12. Negative: negates a color channel
  13. RemoveChannel: remove a color channel
  14. Punch: distorts the image

MirrorOrientation

Mirror orientation.

Values

  1. Vertical: a vertical mirror
  2. Horizontal: an horizontal mirror

Method

Search method. [Added in Actionaz 3.7.0.]

Values

  1. CorrelationCoefficient: correlation coefficient, best for most use cases
  2. CrossCorrelation: cross correlation
  3. SquaredDifference: squared difference
en/code/core/image.txt · Last modified: 2016/10/09 11:10 (external edit)