在当前小程序版本中对于Canvas空间绘制图片,存在bug,效率比较低。
导致图片回执完成慢。出现黑屏。
解决方案:
在调用draw(),绘制成功后,延迟使用绘制结果。例如:500毫秒后,输出图片内容。
ctx.draw(false, function () {
console.info('绘制成功');
setTimeout(function () {
wx.canvasToTempFilePath({
canvasId: 'canvas1',
fileType: 'jpg',
quality: 1,
success: res => {
console.info(res);
_this.setData({ imgPath: res.tempFilePath });
},
fail: res => {
console.error(res);
}
}, this);
},3000);
});
更多: