Skip to content

Crop Screen Shot ​

Crop a specified area from the device screenshot and return the cropped image.

Important Note

This method only returns BMP image format, other formats are not supported.

Interface Description ​

Interface Type ​

cropScreenShot

Parameters ​

ParameterTypeRequiredDescription
deviceIdstringYesDevice ID
rectnumber[]YesCrop area, format: [x1, y1, x2, y2], unit: pixels

Return Value ​

Returns cropped image binary data (BMP format):

Basic Usage ​

javascript
// Crop screenshot
// rect: [x1, y1, x2, y2] - top-left and bottom-right coordinates
const croppedImage = await apiInvoke('cropScreenShot', {
    deviceId: 'P72578581E07',
    rect: [100, 100, 300, 400]  // Area from (100, 100) to (300, 400)
});

// Save as file (Note: returns BMP format)
const fs = require('fs');
fs.writeFileSync('cropped.bmp', croppedImage);

Notes ​

  1. Format Limitation: This method always returns BMP format, other formats cannot be specified
  2. Coordinate Range: Coordinates and dimensions in rect parameter must not exceed screen bounds
  3. Parameter Format: rect must be an array of 4 numbers: [x1, y1, x2, y2], where (x1, y1) is the top-left coordinate and (x2, y2) is the bottom-right coordinate

Cooperation: try.catch@foxmail.com