收藏
回答

canvasToTempFilePath在真实手机上面不运行也不报错?

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 个回答

  • Admin ²º²³
    Admin ²º²³
    2020-02-15
      canvasContext.drawImage(photoFilePath, - width / 2, - height / 2, width, height);
          canvasContext.draw(false, function () {
            // 将生成的canvas图片,转为真实图片
            setTimeout(() => {/* 大坑,Android真机上必须setTimeout延时后保存,不然会出错~~~开发者工具上无问题,ios下也无问题 */
              wx.canvasToTempFilePath({
               }), 2500);
          });
    
    2020-02-15
    有用 1
    回复 1
    • ●﹎Sugar
      ●﹎Sugar
      2020-02-15
      嗯  解决了  2个小时了  才解决  谢谢
      2020-02-15
      回复
  • 🍎
    🍎
    2020-02-15

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

    2020-02-15
    有用
    回复 2
    • ●﹎Sugar
      ●﹎Sugar
      2020-02-15
      额  有示例代码 看看嘛?  谢谢
      2020-02-15
      回复
    • ●﹎Sugar
      ●﹎Sugar
      2020-02-15
      不用了  明白了  粗暴解决了  谢谢
      2020-02-15
      回复
登录 后发表内容
问题标签