为了压缩.jpg文件,这段代码简单地工作。
File pickedFile = await ImagePicker.pickImage(source: ImageSource.gallery);
print('Size in kb: -> ' + (pickedFile.lengthSync() / 1000).toString());
File compressedFile = await ImagePicker.pickImage( source: ImageSource.gallery, imageQuality: 50);
print('Size kb: -> ' + (compressedFile.lengthSync() / 1000).toString());
_uploadFile(compressedFile);
但是如何压缩扩展名为.png的图像文件?
错误:
D/ImageResizer( 6282): image_picker: compressing is not supported for type PNG. Returning the image with original quality
W/ExifInterface( 6282): Invalid image: ExifInterface got an unsupported image format file(ExifInterface supports JPEG and some RAW image formats only) or a corrupted JPEG file to ExifInterface.
1条答案
按热度按时间vaj7vani1#
基于错误,
image_picker
在压缩或更改图像质量时不支持png。您可以使用flutter_image_compress插件,它支持PNG格式。