compressImageFile static method
压缩图片文件
Implementation
static Future<File> compressImageFile(File imageFile,
{int quality = 80}) async {
// 1. 读取图片文件的原始数据
final bytes = await imageFile.readAsBytes();
// 2. 压缩图片数据
final compressedBytes = await compressImageBytes(bytes, quality: quality);
// 3. 创建压缩后的临时文件
final tempDir = await getTemporaryDirectory();
final compressedFile = File('${tempDir.path}/compressed_image.jpg');
// 4. 将压缩后的数据写入临时文件并返回
await compressedFile.writeAsBytes(compressedBytes);
return compressedFile;
}