CanvasContext.getImageData
Get the pixel data of the implicit area of the canvas.
Parameters
It is Object type.
Field | Type | Mandatory | Description |
x | Number | Yes | The x coordinate of left-upper corner of the image rect area that need to be get |
y | Number | Yes | The y coordinate of left-upper corner of the image rect area that need to be get |
width | Number | Yes | The width of the image rect area that need to be get |
height | Number | Yes | The height of the image rect area that need to be get |
success | Function | No | The success callback function |
fail | Function | No | The fail callback function |
complete | Function | No | The 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
}
})