- 开发者工具新Canvas API,绘制图片上传0B,真机无此问题
如题。 提示上传成功 [图片]
2020-07-30 - 点左上角返回按钮 wx.canvasToTempFilePath失败怎么处理?
需求: 用canvas绘图,当页面跳转或其他操作,用canvas绘制图片并上传云服务器。发现当点击左上角返回按钮时,wx.canvasToTempFilePath报errMsg: "canvasToTempFilePath: fail canvas is empty"。请问这种情况下该及时保存用户绘制的图片? [代码]onUnload() {[代码][代码] [代码][代码]// content.draw(true,()=>{[代码][代码] [代码][代码]wx.canvasToTempFilePath({[代码][代码] [代码][代码]canvasId: [代码][代码]'canvas'[代码][代码],[代码][代码] [代码][代码]// destWidth: 500,[代码][代码] [代码][代码]// destHeight: 500,[代码][代码] [代码][代码]success: (res) => {[代码][代码] [代码][代码]console.log(res)[代码][代码] [代码][代码]//保存最后一张图[代码][代码] [代码][代码]this[代码][代码].data.finish_img = res.tempFilePath;[代码][代码] [代码][代码]//设置保存的图片 撤销5笔,保存6个图,不包括当前图[代码][代码] [代码][代码]let chexiao_imgarr = [代码][代码]this[代码][代码].data.chexiao_imgarr;[代码][代码] [代码][代码]chexiao_imgarr.push(res.tempFilePath);[代码][代码] [代码][代码]this[代码][代码].data.chexiao_imgarr = chexiao_imgarr[代码] [代码] [代码][代码]if[代码] [代码](app.globalData.systemInfo.system && app.globalData.systemInfo.system.indexOf([代码][代码]'iOS'[代码][代码]) > -1) { [代码][代码]//苹果系统[代码][代码] [代码][代码]let canvaswidth = [代码][代码]this[代码][代码].data.canvaswidth;[代码][代码] [代码][代码]let revoke_index = chexiao_imgarr.length;[代码][代码] [代码][代码]if[代码] [代码](revoke_index > 0) {[代码][代码] [代码][代码]let current_img = [代码][代码]this[代码][代码].data.chexiao_imgarr[revoke_index - 1];[代码][代码] [代码][代码]content.clearRect(0, 0, canvaswidth, canvaswidth);[代码][代码] [代码][代码]content.drawImage(current_img, 0, 0, canvaswidth, canvaswidth);[代码][代码] [代码][代码]content.draw();[代码][代码] [代码][代码]}[代码][代码] [代码][代码]suncFun && suncFun()[代码][代码] [代码][代码]}[代码][代码] [代码][代码]},[代码][代码] [代码][代码]fail:(err) =>{[代码][代码] [代码][代码]console.log(err)[代码][代码] [代码][代码]}[代码][代码] [代码][代码]},[代码][代码]this[代码][代码])[代码][代码] [代码][代码]// })[代码] [代码] [代码] [代码] [代码][代码]},[代码]
2019-11-13