onReady() {
const query = wx.createSelectorQuery();
query.select('#myCanvas')
.fields({ node: true, size: true })
.exec((res) => {
const canvas = res[0].node
const ctx = canvas.getContext('2d')
const dpr = wx.getSystemInfoSync().pixelRatio
canvas.width = res[0].width * dpr
canvas.height = res[0].height * dpr
ctx.scale(dpr, dpr)
ctx.font = "40px SimHei"
ctx.fillText("Hello world", 0, 50);
const img_url = 'cloud://XXXXXX/aaa.jpg';
wx.getImageInfo({
src: img_url,
success (res2) {
const image = canvas.createImage();
image.src = res2.path;
ctx.drawImage(image,0,0);
}
})
})
}
------------------------------------------------------------------------------------------
Hello world能正常画出来,图片显示不出来,不报错。cloud://XXXXX那个在image控件中显示正常。求各位大佬解惑。
刚提问完就搞定了,Mark一下。
把ctx.drawImage(image,0,0); 改成
image.onload = () => {
ctx.drawImage(image,0,0);
}