createCanvas () {
wx.createSelectorQuery()
.select('#myCanvas')
.fields({
node: true,
size: true,
})
.exec((res) => {
console.log(res)
this.initCanvas(res)
})
},
initCanvas(res) {
const that = this
const width = res[0].width
const height = res[0].height
const canvas = res[0].node
const ctx = canvas.getContext('2d')
const dpr = wx.getSystemInfoSync().pixelRatio
canvas.width = width * dpr
canvas.height = height * dpr
ctx.scale(dpr, dpr)
var img = canvas.createImage()
img.src = 'https://mediabook.oss-cn-shanghai.aliyuncs.com/bangdivr/img/posterbg.jpg'
img.onload = (res) => {
console.log(res)
ctx.drawImage(img ,0, 0, 750, 1448, 0, 0, 750, 1448)
}
img.onerror = (err) => {
console.log(err)
}
},
你好,麻烦提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)