在uniapp中压缩图片可以使用uni.compressImage接口来实现。这个接口可以用来压缩图片,减小图片的尺寸和体积。

示例代码如下:

uni.chooseImage({
  count: 1,
  success: function(res) {
    var tempFilePaths = res.tempFilePaths;
    uni.compressImage({
      src: tempFilePaths[0],
      quality: 80,  // 压缩质量,范围为0-100
      success: function(res) {
        var compressedFilePath = res.tempFilePath;  // 压缩后的图片路径
        // 在这里可以将压缩后的图片上传或者进行其他操作
      },
      fail: function(err) {
        console.log(err);
      }
    });
  },
  fail: function(err) {
    console.log(err);
  }
});

以上代码先使用uni.chooseImage选择图片,然后使用uni.compressImage压缩选中的图片。compressImage的src参数为选中的图片路径,quality参数是压缩质量,值范围为0-100,可以根据需要调整。压缩成功后,可以使用返回的压缩后的图片路径进行上传或其他操作

h5 unichooseImage图片太大上传不了 在uniapp 中怎么压缩图片

原文地址: https://www.cveoy.top/t/topic/hSKx 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录