<canvas type="2d" id="myCanvas"></canvas>
wx.getImageInfo({
src: 'https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTI3GKlCI8afMPe8AoDfokUhiaw1eFWay8z2BH59zks43coenOt6Vd3rK20iaslXcZmGxjdybFt4OYUA/0',
success: function(res) {
const query = wx.createSelectorQuery()
query.select('#myCanvas')
.fields({ node: true, size: true })
.exec((res) => {
const canvas = res[0].node
const ctx = canvas.getContext('2d')
ctx.drawImage(res.path, 0, 0, 100, 100)
ctx.draw()
})
}
})
const query = wx.createSelectorQuery().in(this)
query.select('#myCanvas')
.fields({ node: true, size: true })
.exec((res) => {
console.log(res,'re');
const canvas = res[0].node
let img = canvas.createImage()
img.src = "https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTI3GKlCI8afMPe8AoDfokUhiaw1eFWay8z2BH59zks43coenOt6Vd3rK20iaslXcZmGxjdybFt4OYUA/0"
img.onload = ()=>{
let ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0, 100, 100)
}
})
drawImage传参是一个image对象,请查看官方文档给的代码片段