# wx.canvasGetImageData(Object object, Object this)

Start from base library version 1.9.0. Please remaining backward compatible.

with Promise style call: Supported

Mini Program plugin: Support, need to Mini Program base library version no less than 1.9.6

Obtain canvas The pixel data implied by the region.

# parameter

# Object object

attribute type Default values Required Introductions
canvasId string yes Canvas identity, passed in canvas Component canvas-id Property.
x number yes The upper-left abscissa of the rectangular region of the image data to be extracted
and number yes The upper-left ordinate of the rectangular region of image data to be extracted
width number yes Width of rectangular region of image data to be extracted
height number yes The height of the rectangular area of image data to be extracted
success function no Interface calls the successful callback function
fail function no Interface calls failed callback functions
complete function no Interface calls the end of the callback function (call success or failure will be executed)

# object.success callback

# parameter
# Object res
attribute type Introductions
width number Width of image data rectangle
height number Height of image data rectangle
data Uint8ClampedArray Image pixel data, one-dimensional array, every four items representing a pixel rgba

# Object this

Under a custom component, the this of the current component instance to manipulate within the component canvas assembly

# sample code

Preview with Developer Tool

wx.canvasGetImageData({
  canvasId: 'myCanvas',
  x: 0,
  and: 0,
  width: 100,
  height: 100,
  success(res) {
    console.log(res.width) // 100
    console.log(res.height) // 100
    console.log(res.data instanceof Uint8ClampedArray) // true
    console.log(res.data.length) // 100 * 100 * 4
  }
})