赞
踩
一款简洁实用的图片编辑器,纯dart
开发。支持:涂鸦、旋转&翻转、马赛克、添加文字,及自定义ui风格。
添加依赖
dependencies:
image_editor_dove: ^latest
import
import 'package:image_editor/flutter_image_editor.dart';
获取到原图片后,将其传给ImageEditor
如下:
Future<void> toImageEditor(File origin) async { return Navigator.push(context, MaterialPageRoute(builder: (context) { return ImageEditor( originImage: origin, //可空,支持自定义存储位置(编辑后的图片) savePath: customDirectory ); })).then((result) { if (result is EditorImageResult) { setState(() { _image = result.newFile; }); } }).catchError((er) { debugPrint(er); }); }
返回结果
///The editor's result.
class EditorImageResult {
///宽度
final int imgWidth;
///高度
final int imgHeight;
///编辑后的图片
final File newFile;
EditorImageResult(this.imgWidth, this.imgHeight, this.newFile);
}
一些按钮、滑块等widget
支持自定义,可通过继承ImageEditorDelegate
来自定义ui风格:
class YourUiDelegate extends ImageEditorDelegate{
...
}
ImageEditor.uiDelegate = YourUiDelegate();
class ImageEditor extends StatefulWidget {
const ImageEditor({Key? key, required this.originImage, this.savePath}) : super(key: key);
...
///[uiDelegate] is determine the editor's ui style.
///You can extends [ImageEditorDelegate] and custome it by youself.
static ImageEditorDelegate uiDelegate = DefaultImageEditorDelegate();
@override
State<StatefulWidget> createState() {
return ImageEditorState();
}
}
为了获得更大的绘制区域,所以绘制面积并非为图片显示区域,这也就导致了旋转的时候,相对位置会有变化。如果你需要保持相对,可以控制绘制区域与图片显示区域保持一致即可。
github仓库地址: image_editor_dove
插件地址:image_editor_dove
signature | Flutter Package (flutter-io.cn)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。