CanvasContext.getImageData

Get the pixel data of the implicit area of the canvas.

Parameters

It is Object type.

FieldTypeMandatoryDescription
xNumberYesThe x coordinate of left-upper corner of the image rect area that need to be get
yNumberYesThe y coordinate of left-upper corner of the image rect area that need to be get
widthNumberYesThe width of the image rect area that need to be get
heightNumberYesThe height of the image rect area that need to be get
successFunctionNoThe success callback function
failFunctionNoThe fail callback function
completeFunctionNoThe complete callback function

The Success Return Value

Field|Type|Description
width|Number|The width of the image rect
height|Number|The hight of the image rect

Sample Code

copy
// .js
const ctx = my.createCanvasContext('awesomeCanvas')

ctx.getImageData({
  x: 0,
  y: 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
  }
})