项目地址
本项目是基于image库使用纯dart代码实现的Luban压缩算法,压缩效果个人感觉还可以,目前只能算是beta版本,欢迎大家去github下载示例体验
后续需要优化的问题
1、只支持jpg格式
2、压缩时间有待优化
3、压缩过程中频繁的作内存读写(已解决)
引入
dependencies:
flutter_luban: ^2.1.1
Example
CompressObject compressObject = CompressObject(
imageXFile: imageXFile, //image file
path: tempDir.path, //compress to path, default Directory.systemTemp.path
useCache: true, //If there is a cache, no compression will be performed
toRgb: true, //Convert the image to jpg
numberOfColors: 128, //the numberOfColors of image.quantize
);
Luban.compressImage(compressObject).then((xfile) {
setState(() {
print(xfile.path);
});
});