wx.canvasToTempFilePath 压缩图片在安卓和电脑表现不一致
发布于 5 年前 作者 jie84 6792 次浏览 来自 问答
wx.canvasToTempFilePath({
  x : 0,
  y : 0,
  // destWidth: canvasWidth,
  // destHeight: canvasHeight,
  width: canvasWidth,
  height: canvasHeight,
  fileType: 'jpg',
  quality: 0.9,
  canvasId: 'image-canvas',
  success: function (res) {
    console.log(res.tempFilePath);
    callback ? callback(res.tempFilePath) : '';
  }
})

踩了一个毫无营养价值的坑,用 wx.canvasToTempFilePath 压缩图片时,参考官方文档(如下图),在传入 width 和 height 后省略了destWidth 和 destHeight,在电脑上的表现如预期一样压缩了图片,手机上就不能,好像是直接输出原图?费了大半天时间确认自己的代码没问题之后,补上了 destWidth 和 destHeight ,手机(安卓)也如预期一样压缩了图片。

回到顶部