收藏
回答

"canvasToTempFilePath: fail canvas is em

框架类型 问题类型 操作系统 工具版本
小程序 Bug Windows V1.02.1902010

在draw中调用canvasToTempFilePath失败 步骤:

cxtImg.draw(false, that.saveToImg(mycanvasId))
saveToImg: function (mycanvasId) {
  console.log("3.callback:mycanvasId:::",mycanvasId);
    wx.canvasToTempFilePath({
      x: 0,//画布X轴起点(默认0)
      y: 0,//画布Y轴起点(默认0)
      width: 200,//画布宽度(默认为canvas宽度-x)
      height: 200,//画布高度(默认为canvas高度-x)
      destWidth: 200 * 2, //输出画布宽度(默认为width)
      destHeight: 200 * 2,//输出画布高度(默认为height)
      canvasId: mycanvasId,
      success(res) {
        wx.saveImageToPhotosAlbum({
          imagePath: res.tempFilePath,
        })
        // var tempFilePath=res.tempFilePath;
        console.log("3.输出画布成功!!!tempFilePath:::", tempFilePath);
        // that.data.imagePath = that.data.imagePath.concat(tempFilePath);  
        // console.log("3.输出画布成功!!!that.data.imagePath:::", that.data.imagePath);
        wx.hideToast()
      },
      fail(res) {
        console.log("3.输出画布失败!!!::", res);
      }
    }, this)
  },

控制台输出

输出画布失败!!!:: {errMsg: "canvasToTempFilePath: fail canvas is empty"}


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

2 个回答

  • 2019-06-21

    将wx.canvasToTempFilePath直接作为draw的回调函数,原来把它封装了一下,反而调用失败


    2019-06-21
    有用
    回复 1
    • 2019-06-21

      主要原因是draw的回调没写对,

      cxtImg.draw(false, that.saveToImg(mycanvasId))

      正确写法如下:cxtImg.draw(false, ()=>{      that.saveToImg(mycanvasId)    })

      2019-06-21
      回复
  • 是小白啊
    是小白啊
    2019-06-20

    麻烦提供能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)

    2019-06-20
    有用
    回复 4
登录 后发表内容