我需要上传大量的照片,并将这些照片发送到数据库。由于高质量的照片,它需要相当多的时间来完成和上传每一张照片。我不需要很高质量的照片,所以我需要压缩照片。如果我使用类颤振MultiImagePicker,那么最好的解决方案是什么?
List<Asset> pickedImagesList = await MultiImagePicker.pickImages(maxImages: 25, enableCamera: false);发布于 2020-07-24 08:57:28
您的包已经提出了一些压缩Asset对象的选项。
List<Asset> pickedImagesList = await MultiImagePicker.pickImages(maxImages: 25, enableCamera: false);
for (Asset asset in pickedImagesList) {
ByteData assetData = await asset.getThumbByteData(
width: // desired width,
height: // desired height,
quality: //desired quality,
);
// Send assetData to your database
}编辑
我认为这能让你保持高宽比:
double getAspectRatio(double originalSize, double desiredSize) => desiredSize / originalSize;
final aspectRatio = getAspectRatio(asset.originalWidth, imageDesiredWidth);
ByteData assetData = await asset.getThumbByteData(
width: (asset.originalWidth * aspectRatio).round(),
height: (asset.originalHeight * aspectRatio).round(),
quality: //desired quality,
);发布于 2020-08-07 05:25:45
如果要使用原始宽度和高度而不使用任何操作,请使用
getByteData(quality: 80)相反,
getThumbByteData(quality: 80)https://stackoverflow.com/questions/63069840
复制相似问题