小程序点击使用画布生成图片 第一次 预览显示空白
解决方法
将预览事件写在draw()里面 就可以直接显示了画布内容了
//画入画布
ctx.draw(false, () => {
wx.canvasToTempFilePath({ // 将画布信息转换成 图片展示
x: 0,
y: 10,
width: width - 10,
height: height,
canvasId: 'shareCanvas', //canvas生成的画布id
success(res) {
console.log(res.tempFilePath) //转换的图片
var tempFilePath = res.tempFilePath;
if (tempFilePath !== "") {
wx.previewImage({
current: res.tempFilePath, // 当前显示图片的http链接
urls: [res.tempFilePath], // 需要预览的图片http链接列表
success: function (_res) {
wx.hideLoading()
console.log("预览成功啦");
}
});
}
}
})
})