const ctx = canvas.getContext('2d');
let img = canvas.createImage();
img.src = imgUrl;
img.onload = (e) => {
ctx.drawImage(img, 0, 0, 60, 60);
wx.canvasGetImageData({
canvasId: canvasId,
x: 0,
y: 0,
width: 60,
height: 60,
fail(e){
// 输出canvas内容是 empty, 要如何获取imageData
}
})
};
官方的文档永远只有短短几行字,开发者摸不着头脑,那些人好像是手断了写不了一样,不过也没什么稀奇,毕竟别人垄断了开发者的感受都是次要的
img.onload = (e) => { ctx.drawImage(img, 0, 0, 60, imgHeight 60); const imageData = ctx.getImageData(0, 0, 60, 60); };刚提问玩就找到了,canvas.getContext返回的是RenderingContext,根据文档描述,可以直接使用getImageData获取imageData
看来官方已经把这功能搞废了
参考下文档
https://developers.weixin.qq.com/miniprogram/dev/api/canvas/CanvasContext.drawImage.html
有相关的代码示例
https://developers.weixin.qq.com/miniprogram/dev/api/canvas/wx.createCanvasContext.html