canvas 2d已经画图完成了,导出图片后,点击本地链接图片是空白的
这个代码
/**画布分享链接的海报1 */
canvasImg1: function (template, img, callback) {
let that = this;
let rpx = that.globalData.rpx;
const query = wx.createSelectorQuery()
query.select(template)
.fields({
node: true,
size: true
})
.exec((res) => {
const canvas = res[0].node
const ctx = canvas.getContext('2d')
canvas.width = 442 * rpx
canvas.height = 365 * rpx
const codeImg = canvas.createImage();
codeImg.src = img;
codeImg.onload = () => {
ctx.drawImage(codeImg, 0, 0, 442 * rpx, 264 * rpx, );
ctx.save();
}
const codeImg2 = canvas.createImage();
codeImg2.src = '/images/icon/btn.png';
codeImg2.onload = () => {
ctx.drawImage(codeImg2, 14 * rpx, (264 + 8) * rpx, 396 * rpx, 56 * rpx, );
ctx.save();
}
setTimeout(function () {
wx.canvasToTempFilePath({
canvas,
success(res) {
callback(res.tempFilePath)
}
})
}, 300);
})
},
我也遇到这个问题了,楼主解决了吗,我换回之前的canvas是可以的
因为你没有执行 `draw()`,实际画布不会有任何内容的。