canvasToTempFilePath在真实手机上面不运行也不报错?
发布于 7 年前 作者 aye 14852 次浏览 来自 官方Issues

setTimeout(() => {

      context.draw(true,()=>{

        wx.canvasToTempFilePath({

          x: 0,

          y: 0,

          width: 340,

          height: 500,

          destWidth: 680,

          destHeight: 1000,

          canvasId: 'share',

          success: function (res) {

            console.log(res.tempFilePath)

            wx.saveImageToPhotosAlbum({

              filePath: res.tempFilePath,

              success: (res) => {

                console.log(res)

                that.setData({

                  showModal: false

                })

                wx.hideToast({

                  complete: (res) => {},

                  fail: (res) => {},

                  success: (res) => {},

                })

              },

              fail: (err) => {

                console.log(err)


                that.setData({

                  showModal: false

                })


                wx.hideToast({

                  complete: (res) => {},

                  fail: (res) => {},

                  success: (res) => {},

                })

              }

            })

          },

          fail: function (e) {

            console.log(e)

          }

        })

      });

    }, 1000);

  },

这是运行代码 在开发工具上面能导出图片但是在真实手机上面就运行不起来

2 回复
  canvasContext.drawImage(photoFilePath, - width / 2, - height / 2, width, height);
      canvasContext.draw(false, function () {
        // 将生成的canvas图片,转为真实图片
        setTimeout(() => {/* 大坑,Android真机上必须setTimeout延时后保存,不然会出错~~~开发者工具上无问题,ios下也无问题 */
          wx.canvasToTempFilePath({
           }), 2500);
      });

draw的回调函数没有执行,目前这个问题无解,官方也不修复,目前的粗暴解决办法就是draw后面用settimeoutl来执行导出函数

回到顶部