dart image_picker:PNG类型不支持压缩,如何压缩扩展名为.png的图像文件?

wwwo4jvm  于 2023-06-27  发布在  其他
关注(0)|答案(1)|浏览(215)

为了压缩.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.
vaj7vani

vaj7vani1#

基于错误,image_picker在压缩或更改图像质量时不支持png。您可以使用flutter_image_compress插件,它支持PNG格式。

相关问题