CanvasContext.getImageData
Get the pixel data of the implicit area of the canvas.
Parameters
It is Object type.
Property | Type | Required | 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 | Callback function upon call success. |
fail | Function | No | Callback function upon call failure. |
complete | Function | No | Callback function upon call completion (to be executed upon either call success or failure). |
The Success Return Value
Property | 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
}
})