CanvasContext.getImageData

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

Parameters

It is Object type.

PropertyType

Required

Description
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.
successFunctionNoCallback function upon call success.
failFunctionNoCallback function upon call failure.
completeFunctionNoCallback function upon call completion (to be executed upon either call success or failure).

The Success Return Value

PropertyTypeDescription
widthNumberThe width of the image rect.
heightNumberThe 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
  }
})