收藏
回答

canvasToTempFilePath开发工具正常,手机执行图片被截取,怎么回事?

wx.getImageInfo({
      src: url,//服务器返回的图片地址
      success: function (res) {
        //res.path是网络图片的本地地址
        let Path = res.path;
        let width = res.width;
        let height = res.height;
        let w = (width > height) ? height : width;
        that.setData({
          w: w,
          h: w,
        })
        //let w = width > height ? height : width;
        const ctx = wx.createCanvasContext('share1');
        ctx.drawImage(Path, (w - width) / 2, (w - height) / 2, width, height)
        ctx.save();
        console.log(res)
        ctx.draw(false, () => {
          wx.canvasToTempFilePath({

            canvasId: 'share1',
            success: function (res) {
              that.setData({
                [key]: res.tempFilePath,
                t2:true
              })
            },
            fail(res) {
              console.log(res);
            }
          })
        })
      },
      fail: function (res) {
        //失败回调
      }
    })

工具正常返回最短边像素X最短边像素图片,

手机返回为长方形图片,并且不完整

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

2 个回答

登录 后发表内容
问题标签