收藏
回答

canvasToTempFilePath:fail是怎么回事?

尝试生成海报提示

"canvasToTempFilePath:fail executeCanvasMethod failed: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The image argument is a canvas element with a width or height of 0."


context.draw(false, setTimeout(function(){

      wx.canvasToTempFilePath({

        x: 0,

        y: 0,

        width: 2480,

        height: 3366,

        destWidth: 2480,

        destHeight: 3366,

        canvasId: 'share',

        fileType: 'jpg',

        success: function(res) {

          that.setData({

            shareImgPath: res.tempFilePath

          })

          if (!res.tempFilePath{

            wx.showModal({

              title: '提示',

              content: '图片绘制中,请稍后重试',

              showCancel: false

            })

          }

          //画板路径保存成功后,调用方法吧图片保存到用户相册

          wx.saveImageToPhotosAlbum({

            filePath: res.tempFilePath,

            //保存成功失败之后,都要隐藏画板,否则影响界面显示。

            success: (res) => {

              // console.log(res)

              wx.hideLoading()

              that.setData({

                canvasHidden: true

              })


              wx.showModal({

                title: '保存成功',

                content: '已保存到相册,快去分享吧~',

                showCancel: false

              })

            },

            fail: (err) => {

              console.log(err)

              wx.hideLoading()

              that.setData({

                canvasHidden: true

              })

            }

          })

        },

        fail: (err) => {

          console.log(err)

        }

      })

    },300));


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

3 个回答

  • 一笑皆春
    一笑皆春
    21小时前

    canvas默认给个固定的宽高

    21小时前
    有用
    回复
  • 正好时光
    正好时光
    22小时前

    去掉canvas中的判断显示隐藏canvasHidden,改为定位超出屏幕看不到

    22小时前
    有用
    回复
  • hello world
    hello world
    22小时前

    canvas不加display:none

    22小时前
    有用
    回复 1
    • Lee
      Lee
      22小时前
      wxml里这么写的,没写display
      22小时前
      回复
登录 后发表内容