收藏
回答

点左上角返回按钮 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)
    // })
 
  
  },


回答关注问题邀请回答
收藏

1 个回答

  • 雨竹
    雨竹
    2019-11-13

    已找到解决思路:设置该页面navigationStyle 为custom,自己写导航栏,自己写返回事件

    2019-11-13
    有用 1
    回复
登录 后发表内容
问题标签