github:https://pub.flutter-io.cn/packages/flutter_native_image
网络上找不到一个可以免费使用的图片剪裁编辑工具,由于公司app用户都是网络白痴,flutter的库非常多,自己搞一个,基本都是copy网络代码.
上一篇日志里主要是打开图片,保存图片,这里写一下图片的压缩。
安装库
添加以下代码到pubspec.yaml
#在dependencies:下面添加
flutter_native_image: ^0.0.5
使用
//引用 或者叫导入
import 'package:flutter_native_image/flutter_native_image.dart';
//我使用的代码,换了多个位置,只有在文件打开时能有。有大神知道怎么回事请告诉我以下qq138029200。
if (imageSource != null) {
final file = await ImagePicker.pickImage(source: imageSource);
if (file != null) {
ImageProperties properties =
await FlutterNativeImage.getImageProperties(file.path);
File compressedFile = await FlutterNativeImage.compressImage(file.path,
quality: 90,
targetWidth: 1600,
targetHeight:
(properties.height * 1600 / properties.width).round());
setState(() => imageFile = compressedFile);
}
}
© 版权声明
文章版权归作者所有,未经允许请勿转载。