"canvasToTempFilePath: fail canvas is em
发布于 6 年前 作者 chaozhao 11482 次浏览 来自 问答

在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 回复

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

回到顶部