如何从 multi_image_picker flutter 中压缩图像资源?

How to compress image asset from multi_image_picker flutter?

使用的库:https://pub.dev/packages/multi_image_picker, https://pub.dev/packages/flutter_image_compress

我正在使用多图像选择器库从图库中获取多张图像。但是,在上传它们之前,我想先压缩图像的大小。

多图像选择器 return List<Asset> 但是在 flutter_image_compress 库中,我们只能将图像压缩为这样的文件类型:

Future<Uint8List> testCompressFile(File file) async {
    var result = await FlutterImageCompress.compressWithFile(
      file.absolute.path,
      minWidth: 2300,
      minHeight: 1500,
      quality: 94,
      rotate: 90,
    );
    return result;
  }

如何将 List<Asset> 转换为 List<File> 以压缩图像?

我解决了这个问题。请在此处查看我的完整源代码:https://soksereyphon8.medium.com/upload-multiple-images-and-compress-image-in-flutter-62d113a3247a