这段保存的代码在调试器里可以用,正常导出canvas变成图片,但是是真机安卓保存图片就没有触发ctx.draw() ,苹果触发了也是图片空白的情况,如果拿掉ctx.draw()回调的话那么wx.canvasToTempFilePath 保存的海报里的图片为空白的情况
saveImg() {
// 按照设备比例去计算图片和画布尺寸
let bili = this.InfoSync.windowWidth / 375 * 1;
const ctx = wx.createCanvasContext('posterCanvas');
let _this = this
console.log('开始绘制-');
ctx.draw(true, function () {
wx.canvasToTempFilePath({
x: 0,
y: 0,
width: 310 * bili,
height: 435 * bili,
destWidth: 310 * bili * _this.InfoSync.pixelRatio * 2,
destHeight: 435 * bili * _this.InfoSync.pixelRatio * 2,
fileType: "jpg",
quality: 1,
canvasId: "posterCanvas",
success: function (res) {
wx.hideLoading();
console.log('图片生成成功-', res.tempFilePath);
var tempFilePath = res.tempFilePath;
// 需要权限
wx.saveImageToPhotosAlbum({
filePath: tempFilePath,
success(res) {
wx.showModal({
content: "图片已保存到相册,赶紧晒一下吧~",
showCancel: false,
confirmText: "好的",
confirmColor: "#333"
});
},
fail: function (res) {
wx.hideLoading();
wx.showToast({
title: "已取消",
icon: "none",
duration: 2000
});
}
});
},
fail: err => {
wx.hideLoading();
wx.showToast({
title: "出现了错误,请稍后再试",
icon: "none"
});
}
})
})
},
请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。