https://developers.weixin.qq.com/miniprogram/dev/api/canvas/wx.canvasGetImageData.html
wx.canvasGetImageData({
canvasId: 'canvasBox',
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
},
complete(res) { console.log( res ) }
})
{errMsg: "canvasGetImageData: fail canvas is empty"} api不生效
补充:如果是canvas 2d 要用 ctx.getImageData(x,y,width,height);
如果你在自定义组件使用wx.canvasGetImageData({...},this),wx.canvascreateCanvasContext({...},this)等API,后面都要加一个this参数,文档有写,但真是不明显...
错误提示很明显,没有获取到canvas
麻烦提供能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)
可否提供下代码片段