收藏
回答

如何保存Canvas画好的图片?

        wx.createSelectorQuery()

          .in(this)

          .select('#myCanvas')

          .fields({ node: true, size: true })

          .exec((res) => {

            console.log('res' ,res)

            this.canvas = res[0].node

            this.canvasContext = this.canvas.getContext('2d')

            

            this.canvasWidth = res[0].width

            this.canvasHeight = res[0].height

用的是最新的canvas

        wx.canvasToTempFilePath({

          x: 0,

          y: 0,

          width: this.canvas.width,

          height: this.canvas.height,

          // destWidth: 400,

          // destHeight: 500,

          canvasId: 'myCanvas',

          fileType: 'png',

          success(res) {

           console.log('保存画布成功' ,res)

          },

          fail(err){

            console.log('保存画布失败' ,err)  

          }

        });

保存图片失败,errMsg: "canvasToTempFilePath:fail fail canvas is empty",不知道该如何操作了,API里也没有相关说明,求解?

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

1 个回答

  • Hlxuan.
    Hlxuan.
    01-31

    canvas type="2d" 时需使用 canvas 属性,你没有传这个属性。

    01-31
    有用 1
    回复 1
    • _qin风
      _qin风
      19小时前
      好的,谢谢呀
      19小时前
      回复
登录 后发表内容