color

Device screen color analysis and recognition module [Color]

This module provides a collection of methods for pixel color reading, comparison, and matching
on Android device screens. It is designed for use in automated scripts within the Total Control system.

All functions are dynamically attached to Device.prototype, enabling direct calls such as:
device.getColorBits(), device.compareColor(...), device.seekColor(...), etc.

Key Features

  • Pixel Color Reading: Get RGB or hexadecimal color values of specific screen pixels.
  • Color Comparison:
    • Match a pixel with multiple candidate colors or color ranges.
    • Multi-point comparison for UI validation.
  • Color Search:
    • Locate color points or patterns on the screen or in memory screenshots.
    • Support directional search, similarity thresholds, and fast memory-based lookup.
  • Color Count: Count how many distinct colors exist in a given region.
  • Color Wait: Wait for specific colors to appear before proceeding.

Memory Image Support

Several APIs (e.g., compareColor, seekColor) support memory-based input using "@0", "@1", "@2", or "@@".
You must prepare these buffers with device.screenshotToMemory("@0"), etc.

Example Usage

var color = require("sigma/color");
var { Device } = require('sigma/device');
var sigmaDevice = Device.getMain();
var count = sigmaDevice.getColorCount(0, 0, 360, 540);
print("Color count: " + count);

(inner) compareColor(locationOrX, x, y, colors, sim) → {number}

Compares the pixel color(s) at a specified screen coordinate with one or more expected color values, and the color is expressed in hexadecimal, such as "0x001122".
Supports matching directly on the current screen or a previously captured memory image.

Supports:
compareColor(x, y, colors, sim)
compareColor(location,x, y, colors, sim)

The colors parameter supports single or multiple color formats:

  • "0xff0000": a single color (pure red)
  • "0xff0000|0x00ff00": multiple expected values (OR logic)
  • "0xff0000-0x00ff00": range between two colors (inclusive)
  • You can combine multiple logic units using | and -

If location (e.g. "@0") is provided as the first argument, the check is performed on that memory image.
The function returns the index (starting from 0) of the matched color in the list, or -1 if no match.

Example
// Example 1: Compare color at position (578, 621) on the current screen
var color = require("sigma/color");
var { Device } = require('sigma/device');
var sigmaDevice = Device.getMain();
if (sigmaDevice != null) {
    var ret = sigmaDevice.compareColor(578, 621, "0xff0000|0x35515e-0x5a9fe4|0xf7f7f7", 1.0);
    if (ret >= 0) {
        print("Congratulations, this API executes successfully.\nReturn value: " + ret);
    } else {
        print("Sorry! " + lastError() + "\nReturn value: " + ret);
    }
} else {
    print("Failed to get the master device object");
}


// Example 2: Compare color using memory image "@0"
var color = require("sigma/color");
var image = require("image");
var { Device } = require('sigma/device');
var sigmaDevice = Device.getMain();
if (sigmaDevice != null) {
    var ret1 = sigmaDevice.screenshotToMemory("@0");
    if (ret1 === 0) {
        var ret = sigmaDevice.compareColor("@0", 578, 621, "0xff0000|0x35515e-0x5a9fe4|0xf7f7f7", 1.0);
        if (ret >= 0) {
            print("Congratulations, this API executes successfully.\nReturn value: " + ret);
        } else {
            print("Sorry! " + lastError() + "\nReturn value: " + ret);
        }
    } else {
        print("screenshotToMemory Error: " + lastError());
    }
} else {
    print("Failed to get the master device object");
}

// Operation Result:
// Congratulations, this API executes successfully.
// Return value: 2
Parameters:
string | number locationOrX

Either the memory location (e.g. "@0") or the x-coordinate.

number x

The x-coordinate of the pixel to check (if location is provided).

number y

The y-coordinate of the pixel.

string colors

One or more expected colors in hex format. Supports OR | and range - logic.

number sim

Similarity threshold between 0.0 and 1.0 (e.g., 1.0 = exact match).

Returns:
number

The index of the matched color (starting from 0), or -1 if none matched. Returns < 0 on error.

(inner) compareColorEx(locationOrPoints, pointsOrSim, simopt) → {boolean}

Performs a multi-point color comparison to determine whether all specified screen coordinates match their corresponding expected color(s),

Supports:
compareColorEx(points, sim)
compareColorEx(location, points, sim)

within a given similarity threshold. The method supports:

  • Array-based format: [[x, y, color], ...]
  • String-based format: "x|y|color1|color2,..."
  • Optional use of a memory image location as source ("@0", "@1" etc.)

The function returns true if all points match at least one of their specified colors; otherwise returns false.

Example
// Example 1: Compare multiple color points on the current screen (array form)
var color = require("sigma/color");
var { Device } = require('sigma/device');
var sigmaDevice = Device.getMain();
if (sigmaDevice != null) {
    var ret = sigmaDevice.compareColorEx([
        [32, 621, "0x4a90d5|0xff0000-0xffffff"],
        [100, 421, "0x579cdf|0x9c1f8"],
        [500, 225, "0x589dde"]
    ], 0.7);
    if (ret === true) {
        print("Congratulations, this API executes successfully.\nReturn value: " + ret);
    } else {
        print("Sorry! " + lastError() + "\nReturn value: " + ret);
    }
}


// Example 2: Using a string-form multi-color definition on current screen
var color = require("sigma/color");
var { Device } = require('sigma/device');
var sigmaDevice = Device.getMain();
if (sigmaDevice != null) {
    var ret = sigmaDevice.compareColorEx("32|621|0x9c1f8|0xff0000-0xffffff,77|421|0x6fa913|0x9c1f8-0xffffff", 0.9);
    if (ret === true) {
        print("Congratulations, this API executes successfully.\nReturn value: " + ret);
    } else {
        print("Sorry! " + lastError() + "\nReturn value: " + ret);
    }
}

// Example 3: Using memory location "@0" with array format
var color = require("sigma/color");
var image = require("image");
var { Device } = require('sigma/device');
var sigmaDevice = Device.getMain();
var ret1 = sigmaDevice.screenshotToMemory("@0");
if (ret1 === 0) {
    var ret = sigmaDevice.compareColorEx("@0", [
        [32, 621, "0x4a90d5|0xff0000-0xffffff"],
        [100, 421, "0x579cdf|0x9c1f8"],
        [500, 225, "0x589dde"]
    ], 0.7);
    if (ret === true) {
        print("Congratulations, this API executes successfully.\nReturn value: " + ret);
    } else {
        print("Sorry! " + lastError() + "\nReturn value: " + ret);
    }
}


// Example 4: Using memory image and string format
var color = require("sigma/color");
var image = require("image");
var { Device } = require('sigma/device');
var sigmaDevice = Device.getMain();
var ret1 = sigmaDevice.screenshotToMemory("@0");
if (ret1 === 0) {
    var ret = sigmaDevice.compareColorEx("@0", "32|621|0x9c1f8|0xff0000-0xffffff,77|421|0x6fa913|0x9c1f8", 1.0);
    if (ret === true) {
        print("Congratulations, this API executes successfully.\nReturn value: " + ret);
    } else {
        print("Sorry! " + lastError() + "\nReturn value: " + ret);
    }
}

// Operation Result:
// If it executes successfully:
Congratulations, this API executes successfully.
Return value: true
Parameters:
string | Array locationOrPoints

Either:

  • A memory location (e.g. "@0") when comparing from a stored screenshot
  • Or a color point list (either array or string form)
Array | number pointsOrSim

If location is provided: the color points array or string. Otherwise: the similarity value.

number sim <optional>

The similarity threshold between 0.0 ~ 1.0 (e.g. 0.9 = 90% match). Required only when location is specified.

Returns:
boolean

true if all color checks passed; false if any failed; < 0 if error (use lastError() to debug).

(inner) getColorBits() → {number}

Returns the color depth (bits per pixel) of the connected Android device's screen.
This information is useful when performing image processing, color recognition, or configuring display-based automation.

The color depth is the maximum number of colors supported. It is generally described by "bits".
Common return values:

  • 16 — 16-bit color depth
  • 24 — 24-bit color depth
  • 32 — 32-bit color depth (typical for modern devices)
Example
// Example: Query the screen color depth
var color = require("sigma/color");
var { Device } = require('sigma/device');
var sigmaDevice = Device.getMain();
if (sigmaDevice != null) {
    var ret = sigmaDevice.getColorBits();
    if (ret != 0) {
        print("Congratulations, this API executes successfully.\nReturn value: " + ret);
    } else {
        print("Sorry! " + lastError() + "\nReturn value: " + ret);
    }
} else {
    print("Failed to get the master device object");
}

// Operation Result:
// If successful:
Congratulations, this API executes successfully.
Return value: 32
Returns:
number

The color depth of the device screen. Returns 0 on failure (check with lastError()).

(inner) getColorCount(locationOrX1, x1, y1, x2, y2) → {number}

Counts the number of distinct colors in a specified rectangular region of the screen or memory screenshot.
Supports analyzing the current screen or a previously captured memory image.

If location is provided as the first argument (e.g. "@0"), the function uses the memory image stored at that location.
Otherwise, the function analyzes the current screen content directly.

Supports:
getColorCount(x1, y1, x2, y2)
getColorCount(location, x1, y1, x2, y2)

Note:
When we look for images, find colors, and recognize text, we can reuse the image data stored in the memory location, and it is faster to find, find, and recognize text.
But when we use memory to find colors, first we need to make sure that the memory location @0, @1 or @2 is available;
To ensure that the memory location is available, you can first use the API "screenshotToMemory" to specify the memory location where you want to store the data. The life cycle of in-memory data is the same as the life cycle of the Total Control application on the mobile phone. That is to say, as long as we do not close the Total Control application on the mobile terminal, we only need to use the “screenshotToMemory” API for each memory location to specify the memory location.
For example, take a screenshot to memory and specify the memory location "@0" to store the data.
var { Device } = require('sigma/device');
var sigmaDevice = Device.getMain();
var image = require("image");
sigmaDevice.screenshotToMemory("@0");

Example
// Example 1: Count distinct colors from the current screen region (0, 0, 360, 540)
var color = require("sigma/color");
var { Device } = require('sigma/device');
var sigmaDevice = Device.getMain();
if (sigmaDevice != null) {
    var ret = sigmaDevice.getColorCount(0, 0, 360, 540);
    if (ret > 0) {
        print("Congratulations, this API executes successfully.\nReturn value: " + ret);
    } else {
        print("Sorry! " + lastError() + "\nReturn value: " + ret);
    }
} else {
    print("Failed to get the master device object");
}


// Example 2: Count colors using a screenshot stored in memory location "@0"
var color = require("sigma/color");
var image = require("image");
var { Device } = require('sigma/device');
var sigmaDevice = Device.getMain();
if (sigmaDevice != null) {
    var ret1 = sigmaDevice.screenshotToMemory("@0");
    if (ret1 === 0) {
        var ret = sigmaDevice.getColorCount("@0", 0, 0, 360, 540);
        if (ret > 0) {
            print("Congratulations, this API executes successfully.\nReturn value: " + ret);
        } else {
            print("Sorry! " + lastError() + "\nReturn value: " + ret);
        }
    } else {
        print("screenshotToMemory Error: " + lastError());
    }
} else {
    print("Failed to get the master device object");
}

// Operation Result:
// If it executes successfully:
Congratulations, this API executes successfully.
Return value: 6843
Parameters:
string | number locationOrX1

The specified memory stores the location of the data; @0, @1 or @2 represents a fixed three memory locations, and "@@" represents the last memory screenshot.
or the X coordinate of the upper left corner of the specified range on the screen;

number x1

The top-left x-coordinate (if location is specified).

number y1

The top-left y-coordinate of the region.

number x2

The bottom-right x-coordinate of the region.

number y2

The bottom-right y-coordinate of the region.

Returns:
number

The number of colors in the specified area of the screen, the minimum value is 1, zero means failure. Specific error information can be obtained by the lastError() function.

(inner) getPixelColor(locationOrX, xopt, yopt) → {Object|null}

Retrieves the RGB color of the pixel at the specified screen coordinate.

Supports:
getPixelColor(x, y)
getPixelColor(location, x, y)

The function can operate on either:

  • The current screen (default usage), or
  • A previously captured memory image (e.g., "@0", "@1") if a location is specified.

The returned object includes red, green, and blue values in the range 0–255.

Example
// Example 1: Get the color of a pixel at (578, 621) from the current screen
var color = require("sigma/color");
var { Device } = require('sigma/device');
var sigmaDevice = Device.getMain();
if (sigmaDevice != null) {
    var ret = sigmaDevice.getPixelColor(578, 621);
    if (ret != null) {
        print("Congratulations, this API executes successfully.\nReturn value: " + ret);
        print("Red: " + ret.red);
        print("Green: " + ret.green);
        print("Blue: " + ret.blue);
    } else {
        print("Sorry! " + lastError() + "\nReturn value: " + ret);
    }
} else {
    print("Failed to get the master device object");
}


// Example 2: Get pixel color from a memory screenshot ("@0")
var color = require("sigma/color");
var image = require("image");
var { Device } = require('sigma/device');
var sigmaDevice = Device.getMain();
if (sigmaDevice != null) {
    var ret1 = sigmaDevice.screenshotToMemory("@0");
    if (ret1 === 0) {
        var ret = sigmaDevice.getPixelColor("@0", 578, 621);
        if (ret != null) {
            print("Congratulations, this API executes successfully.\nReturn value: " + ret);
            print("Red: " + ret.red);
            print("Green: " + ret.green);
            print("Blue: " + ret.blue);
        } else {
            print("Sorry! " + lastError() + "\nReturn value: " + ret);
        }
    } else {
        print("screenshotToMemory Error: " + lastError());
    }
} else {
    print("Failed to get the master device object");
}

// Operation Result:
Congratulations, this API executes successfully.
Return value: [r=74, g=57, b=74]
Red: 74
Green: 57
Blue: 74
Parameters:
string | number locationOrX

Either the memory location (e.g., "@0") or the x-coordinate of the pixel.

number x <optional>

The x-coordinate of the pixel (if location is provided).

number y <optional>

The y-coordinate of the pixel.

Returns:
Object | null

An object representing the RGB values if successful; otherwise null (use lastError() to check error).

(inner) getPixelColorStr(locationOrX, xopt, yopt) → {string|null}

Retrieves the color value of a pixel at the specified coordinate in hexadecimal string format (e.g., "0xff0000" for red).

Supports:
getPixelColorStr(x, y)
getPixelColorStr(location, x, y)

Supports reading from either the current screen or a previously captured memory screenshot.

If a location (e.g., "@0") is provided, the pixel color is read from the specified memory image.
Otherwise, the current screen is analyzed.

Example
// Example 1: Get color string from pixel (360, 540) on the current screen
var color = require("sigma/color");
var { Device } = require('sigma/device');
var sigmaDevice = Device.getMain();
if (sigmaDevice != null) {
    var ret = sigmaDevice.getPixelColorStr(360, 540);
    if (ret != null) {
        print("Congratulations, this API executes successfully.\nReturn value: " + ret);
    } else {
        print("Sorry! " + lastError() + "\nReturn value: " + ret);
    }
} else {
    print("Failed to get the master device object");
}


// Example 2: Get color string from memory screenshot "@0"
var color = require("sigma/color");
var image = require("image");
var { Device } = require('sigma/device');
var sigmaDevice = Device.getMain();
if (sigmaDevice != null) {
    var ret1 = sigmaDevice.screenshotToMemory("@0");
    if (ret1 === 0) {
        var ret = sigmaDevice.getPixelColorStr("@0", 360, 540);
        if (ret != null) {
            print("Congratulations, this API executes successfully.\nReturn value: " + ret);
        } else {
            print("Sorry! " + lastError() + "\nReturn value: " + ret);
        }
    } else {
        print("screenshotToMemory Error: " + lastError());
    }
} else {
    print("Failed to get the master device object");
}

// Operation Result:
// If it executes successfully:
Congratulations, this API executes successfully.
Return value: 0x4a394a
Parameters:
string | number locationOrX

Either the memory location string (e.g. "@0") or the x-coordinate.

number x <optional>

The x-coordinate of the pixel (if location is provided).

number y <optional>

The y-coordinate of the pixel.

Returns:
string | null

The pixel color in hex string format ("0xRRGGBB"), or null if an error occurred (use lastError()).

(inner) seekColor(x1opt, y1opt, x2opt, y2opt, options) → {Object|Boolean|null}

Searches for a pixel or region on the screen that matches the given color(s), either from the current screen or a memory image.

Supports:
seekColor({options})
seekColor(x1, y1, x2, y2, {options})

Supports:

  • Single color or multiple offset-based color relationships
  • Full-screen or region-limited search
  • Optional use of memory screenshots (via location)

The function returns:

  • For single-point color: { x: number, y: number } or an array of such points (if seekAll: true)
  • For multi-point color: { x, y, rect: [x1, y1, x2, y2] }
  • null on failure (check lastError())
Example
// Example 1: Single-point color search in full screen
var color = require("sigma/color");
var { Device } = require('sigma/device');
var sigmaDevice = Device.getMain();
var coor = sigmaDevice.seekColor({
    primaryColor: "0x000000-0xffffff",
    sim: 1,
    dir: 4,
    seekAll: true
});
if (coor) {
    coor.forEach(c => print("(" + c.x + "," + c.y + ")"));
}


// Example 2: Single-point color search in region
var color = require("sigma/color");
var { Device } = require('sigma/device');
var sigmaDevice = Device.getMain();
var coor = sigmaDevice.seekColor(0, 0, 719, 1110, {
    primaryColor: ["0x0000ff", "0x00ff00", "0x0000dd-0x0000ff"],
    sim: 1,
    dir: 4
});
if (coor) {
    print("Found: (" + coor.x + "," + coor.y + ")");
}


// Example 3: Multi-point color search in full screen
var color = require("sigma/color");
var { Device } = require('sigma/device');
var sigmaDevice = Device.getMain();
var coor = sigmaDevice.seekColor({
    primaryColor: "0x000000-0xffffff",
    secondaryColor: "-10|5|0x05beef,5|-10|0xaaaaaa-0xbbbbbb",
    sim: 1,
    dir: 4
});
if (coor) {
    print("Coord: (" + coor.x + "," + coor.y + "), Rect: " + JSON.stringify(coor.rect));
}


// Example 4: Search in a memory image region with array-form secondary colors
var color = require("sigma/color");
var { Device } = require('sigma/device');
var sigmaDevice = Device.getMain();
var image = require("image");
var ret1 = sigmaDevice.screenshotToMemory("@0");
if (ret1 === 0) {
    var coor = sigmaDevice.seekColor(0, 0, 719, 1110, {
        primaryColor: "000000-ffffff",
        secondaryColor: ["-10|5|0x05beef", "5|-10|0xaaaaaa-0xbbbbbb"],
        sim: 1,
        dir: 4,
        location: "@0"
    });
    if (coor) {
        print("Coord: (" + coor.x + "," + coor.y + "), Rect: " + JSON.stringify(coor.rect));
    }
}

// Operation Result:
Single-point: { x: 719, y: 50 }
Multi-point: { x: 719, y: 50, rect: [685, 26, 733, 74] }
Parameters:
number x1 <optional>

(Optional) The top-left x-coordinate of the region to search.

number y1 <optional>

(Optional) The top-left y-coordinate of the region.

number x2 <optional>

(Optional) The bottom-right x-coordinate of the region.

number y2 <optional>

(Optional) The bottom-right y-coordinate of the region.

Object options

The color search parameters:

Properties
string | Array.<string> primaryColor

Target color(s), single or multiple, only hex colors are supported (0x can be omitted), multiple colors are separated by "|", if you need to compare the range of colors, separated by "-", e.g. "0x0000ff" or ["0x0000ff", "0xff0000-0xffffff"]
For example:

  • Array format: ["0x0000ff", "0x00ff00", "0x0000dd-0x0000ff"] or ["0000ff", "00ff00", "0000dd-0000ff"]
  • String format: "0x0000ff | 0x00ff00 | 0x0000dd-0x0000ff" or "0000ff | 00ff00 | 0000dd-0000ff"
string | Array.<string> secondaryColor <optional>

Secondary colors to be compared, multiple secondary colors can be given at the same time, and multiple secondary colors are separated by commas.
Secondary color format: x offset from primary color | y offset from primary color | hexadecimal color.
Hexadecimal color (0x can be omitted), multiple colors are separated by "|", if you need to compare the range of colors, separated by "-".
Example:

  • Array format: ["-10 | 5 | 0x05beef", "5 | -10 | 0xaaaaaa-0xbbbbbb"] or ["5 | 0 | aabbcc", "-5 | 0 | aabbdd | aaaaaa-cccccc", "0 | 5 | bbccdd | 000000-111111"]
  • String format: "-10 | 5 | 0xccddee | 0xaabbcc-0xaabbcc" or "-10 | 5 | 0x05beef, 5 | -10 | 0xaaaaaa-0xbbbbbb" or "5 | 0 | aabbcc, -5 | 0 | aabbdd | aaaaaa-cccccc, 0 | 5 | bbccdd | 000000-111111"
number sim

Similarity: The value range is [0.0, 1.0]. 1.0 represents a perfectly matched. The smaller the value of sim, the lower the requirement for similarity.

number dir

Search direction. The value is 0-4. The meaning of the value is as follows:

  • 0: means looking up from top left to bottom right;
  • 1: means looking up from the center to the surroundings;
  • 2: means looking from the lower right to the upper left;
  • 3: means looking from bottom left to top right;
  • 4: means looking up from the top right to the bottom left;
boolean seekAll <optional>
false

Whether to find all matching points (returns array) or just the first match

string location <optional>

Specify where to store data in memory.
"@0", "@1" and "@2" means three fixed memory locations, and "@@" means the last memory screenshot.
Notes when use @@ :When using @@ to specify location, first find if the last memory screenshot is available, if it is available, use it directly;
If last memory screenshot is empty (e.g. erased by screenshotClearMemory()), use the first non-empty buffer, from @0 to @2;
if all screen buffers are empty, call screenshotToMemory("@0") and use "@0" as last buffer.

Returns:
Object | Boolean | null

There is a slight difference between the domestic version and the international version. The details are as follows. If you don't know the build type, you can check it through getSetting(tcConst.BuildCountryCode), where cn indicates the domestic version and us indicates the international version.
Domestic version:
If the API is successfully executed and the specified color is successfully found, the js object is returned, the coordinates of the first pixel with the same color as the specified color, for example: {x: , y: };
if it is a multi-point color search, returns coordinates and area, for example {x: , y: , rect: [x1, y1, x2, y2]}.
If the API is executed successfully, but the specified color is not found, null is returned.
If the API fails to execute, return null, you can get the error information by "lastError()"

International version:
If the API is successfully executed and the specified color is successfully found, the js object is returned, the coordinates of the first pixel with the same color as the specified color, for example: {x: , y: };
if it is a multi-point color search, return coordinates and area, for example {x: , y: , rect: [x1, y1, x2, y2]}.
If the API is executed successfully, but the specified color is not found, false is returned.
If the API fails to execute, return null, you can get the error information by "lastError()"

(inner) waitForColor(x1, y1, x2, y2, color, dir, sim, timeout) → {Object|null}

Waits until a specified color appears in a given rectangular region on the screen, or until a timeout is reached.
This is typically used to synchronize automation steps with dynamic UI elements.

The method continuously checks for the presence of the target color(s) within the specified rectangle,
returning the first matched coordinate once found.

Supports:
waitForColor(x1, y1, x2, y2, color, dir, sim, timeout)
waitForColor(location, x1, y1, x2, y2, color, dir, sim, timeout)

"@0", "@1" and "@2" means three fixed memory locations, and "@@" means the last memory screenshot.

Example
// Example 1: Wait up to 20 seconds for a specific color to appear in a 500x500 region
var color = require("sigma/color");
var { Device } = require('sigma/device');
var sigmaDevice = Device.getMain();
if (sigmaDevice != null) {
    var ret = sigmaDevice.waitForColor(
        0, 0, 500, 500,
        "0xffffff|0xaabbcc-0x000000|0x00ff00-0x101010",
        1, 1.0, 20000
    );
    if (ret != null) {
        print("Congratulations, this API executes successfully.\nReturn value: (" + ret.x + "," + ret.y + ")");
    } else {
        print("Sorry! " + lastError() + "\nReturn value: " + ret);
    }
} else {
    print("Failed to get the master device object");
}

// Operation Result:
// If successful:
Congratulations, this API executes successfully.
Return value: (85,39)

// Example 2: Wait up to 20 seconds for a specific color to appear in a 500x500 region in a memory image region
var color = require("sigma/color");
var { Device } = require('sigma/device');
var sigmaDevice = Device.getMain();
var image = require("image");
var screenshot = sigmaDevice.screenshotToMemory("@0");
if (screenshot === 0) {
     var ret = sigmaDevice.waitForColor(
        "@0",
        0, 0, 500, 500,
        "0xffffff|0xaabbcc-0x000000|0x00ff00-0x101010",
        1, 1.0, 20000
    );
    if (ret != null) {
        print("Congratulations, this API executes successfully.\nReturn value: (" + ret.x + "," + ret.y + ")");
    } else {
        print("Sorry! " + lastError() + "\nReturn value: " + ret);
    }
}
Parameters:
number x1

The top-left x-coordinate of the search region.

number y1

The top-left y-coordinate of the search region.

number x2

The bottom-right x-coordinate of the search region.

number y2

The bottom-right y-coordinate of the search region.

string color

One or more target colors to detect. Supports:

  • Single color: "0xff0000"
  • OR logic: "0xff0000|0x00ff00"
  • Color range: "0x000000-0x666666"
  • Combined: "0xffffff|0xaabbcc-0x000000|0x00ff00-0x101010"
number dir

Find directions.

  • 0: means looking up from top left to bottom right;
  • 1: means looking up from the center to the surroundings;
  • 2: means looking from the lower right to the upper left;
  • 3: means looking from bottom left to top right;
  • 4: means looking up from the top right to the bottom left;
number sim

Similarity, the default is 1.0, the similarity range is [0.0, 1.0].It works only on a single color and is useless for color ranges. 1 means the image is completely matched. The smaller the value of sim, the lower the requirement for similarity.

number timeout

Timeout (milliseconds).

Returns:
Object | null

If successful, it returns the first coordinate of the found color, and the specific coordinate value can be obtained by color.x, color.y ; otherwise, it returns null. Specific error information can be obtained by the lastError() function.