This module provides image processing and screenshot functionality for Android devices controlled via Total Control.
It supports capturing, comparing, and parsing screen images in BMP format, as well as memory-optimized operations and visual element detection.
Key Features:
- Capture screenshots to file, memory, or device storage.
- Find images on screen or in memory using exact or fuzzy matching.
- Wait for target images to appear on screen (
waitForImage). - Read and parse BMP headers, including custom TC Creator metadata (
parseBMP). - Use memory slots (
@0,@1,@2,@@) for faster repeated image operations. - Retrieve raw image data (pixels and metadata) from screen or memory.
Memory Screenshot Workflow:
- Save screenshot to memory with
screenshotToMemory("@0") - Perform operations like
seekImage("@0", ...),getData(2, "@0"), etc. - Clear memory with
screenshotClearMemory("@0")or all with no args.
Image Search Capabilities:
seekImage: Supports multiple forms, including region-based, memory-based, and ImageInfo-based search with adjustable similarity.seekImageByID: Use image mapping JSON to match pre-defined UI elements.waitForImage: Wait for specific images to appear within timeout.
BMP Metadata Parsing:
Use parseBMP(filePath) to extract:
- Standard BMP header (size, dimensions, color depth)
- Optional TC Creator header (original screen region, package name, activity, resolution)
This module attaches Java and JavaScript methods to Device.prototype,
allowing direct method calls on device instances for image-related operations.
Functions
(inner) getData(type, locationopt) → {object|null}
Retrieve image data from the device based on the specified type.
Optionally, you can specify a memory location (e.g., "@0") to retrieve image data from a previously saved screenshot.
getData(tcConst.getData.Screen) : Get screenshot image data from the device
getData(tcConst.getData.Memory) : Get memory image data from the device
Supports:
getData(type)
getData(type,location)
Example
// Example 1: Get image data from memory location "@0"
var { Device } = require("sigma/device");
var image = require("sigma/image");
// Get the current master device object
var sigmaDevice = Device.getMain();
sigmaDevice.screenshotToMemory("@0", 1, 1, 10, 10);
var ret = sigmaDevice.getData(2, "@0");
if (ret != null) {
var info = ret.info;
print("version: " + ret.version);
print("datatype: " + ret.datatype);
print("length: " + ret.length);
print("width: " + info.width);
print("height: " + info.height);
print("data: " + ret.data);
} else {
print("Failed to get data from Memory! " + lastError());
}
// Example 2: Get image data from last screenshot
var { Device } = require("sigma/device");
var image = require("sigma/image");
// Get the current master device object
var sigmaDevice = Device.getMain();
var ret = sigmaDevice.getData(1);
if (ret != null) {
var info = ret.info;
print("version: " + ret.version);
print("datatype: " + ret.datatype);
print("length: " + ret.length);
print("width: " + info.width);
print("height: " + info.height);
print("data: " + ret.data);
} else {
print("Failed to get data from screenshot! " + lastError());
}
// Operation Result:
// If it executes successfully:
version: 1
datatype: 1
length: 300
width: 720
height: 1280
data: "[]"
Parameters:
| number | type |
Two ways to get image data:
|
|
| string | location |
<optional> |
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. |
Returns:
| object | null |
Returns an object containing image metadata and pixel data if successful; otherwise, returns
|
| string | imageName |
The full path of the BMP image file to parse (e.g., "E:\File\test.bmp"). |
Returns:
| object | null |
If successful, returns a JSON object containing the keywords "bmpHeader" and "tcHeader". |
| string | filePathOrLocation |
The path to save the image (e.g., "D:/img/image.jpg") |
|
| string | filePath |
<optional> |
The path to save the image. Required only when the first argument is a memory location. |
| number | imageType |
Image format (e.g., |
|
| number | topLeftX |
<optional> |
Optional. The x-coordinate of the top-left corner of the capture area, do not fill in the coordinate value, indicating a full screen screenshot. |
| number | topLeftY |
<optional> |
Optional. The y-coordinate of the top-left corner of the capture area, do not fill in the coordinate value, indicating a full screen screenshot. |
| number | bottomRightX |
<optional> |
Optional. The x-coordinate of the bottom-right corner of the capture area, do not fill in the coordinate value, indicating a full screen screenshot. |
| number | bottomRightY |
<optional> |
Optional. The y-coordinate of the bottom-right corner of the capture area, do not fill in the coordinate value, indicating a full screen screenshot. |
Returns:
| number |
This function returns 0 on success or -1 on failure. Specific error information can be obtained by the lastError() function. |
| string | location |
<optional> |
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. |
Returns:
| number |
Returns 0 if successful; otherwise, returns a non-zero error code. Use |
| string | filePath |
Save the full path of the screenshot image, such as "/data/local/tmp/tmp.bmp". |
|
| number | imageType |
Image format (e.g., |
|
| number | topLeftX |
<optional> |
Optional. X-coordinate of the top-left corner of the region to capture, do not fill in the coordinate value, indicating a full screen screenshot. |
| number | topLeftY |
<optional> |
Optional. Y-coordinate of the top-left corner of the region to capture, do not fill in the coordinate value, indicating a full screen screenshot. |
| number | bottomRightX |
<optional> |
Optional. X-coordinate of the bottom-right corner of the region to capture, do not fill in the coordinate value, indicating a full screen screenshot. |
| number | bottomRightY |
<optional> |
Optional. Y-coordinate of the bottom-right corner of the region to capture, do not fill in the coordinate value, indicating a full screen screenshot. |
Returns:
| number |
This function returns 0 on success or -1 on failure. Specific error information can be obtained by the lastError() function. |
| string | location |
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. |
|
| number | topLeftX |
<optional> |
Optional. The x-coordinate of the top-left corner of the region to capture, do not fill in the coordinate value, indicating a full screen screenshot. |
| number | topLeftY |
<optional> |
Optional. The y-coordinate of the top-left corner of the region to capture, do not fill in the coordinate value, indicating a full screen screenshot. |
| number | bottomRightX |
<optional> |
Optional. The x-coordinate of the bottom-right corner of the region to capture, do not fill in the coordinate value, indicating a full screen screenshot. |
| number | bottomRightY |
<optional> |
Optional. The y-coordinate of the bottom-right corner of the region to capture, do not fill in the coordinate value, indicating a full screen screenshot. |
Returns:
| number |
This function returns 0 on success or -1 on failure. Specific error information can be obtained by the lastError() function. |
| any | args |
<repeatable> |
Flexible arguments depending on usage. Supported Forms:
|
Returns:
| Object | false | null |
|
| string | imageID |
The image identifier defined in the image mapping file (e.g., "AAA0"). |
|
| number | sim |
<optional> |
Similarity, the default is 1.0, the similarity range is [0.0, 1.0]. 1 means the image is completely matched. The smaller the value of sim, the lower the requirement for similarity. |
Returns:
| Object | null |
If successful, returns the center point coordinate object of the found image, which can be used to obtain the coordinates of the center point, such as coord.x; coord.y; otherwise, it returns null. Specific error information can be obtained by the lastError() function. |
| string | location |
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. |
| string | path |
The absolute path of the image, the image must be in bmp format, For example: "d:/image.bmp". |
| number | sim |
Similarity, the default is 1.0, the similarity range is [0.0, 1.0]. 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, returns the center point coordinate object of the found image, which can be used to obtain the coordinates of the center point, such as coord.x; coord.y; otherwise, it returns null. Specific error information can be obtained by the lastError() function. |