Flutter簡潔實用的圖片編輯器的實現(xiàn)
介紹
一款簡潔實用的圖片編輯器,純dart開發(fā)。支持:涂鴉、旋轉(zhuǎn)&翻轉(zhuǎn)、馬賽克、添加文字,及自定義ui風格。
功能演示
涂鴉

旋轉(zhuǎn)&翻轉(zhuǎn)

馬賽克

添加文字及刪除


安裝
添加依賴
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);
});
}
返回結(jié)果
///The editor's result.
class EditorImageResult {
///寬度
final int imgWidth;
///高度
final int imgHeight;
///編輯后的圖片
final File newFile;
EditorImageResult(this.imgWidth, this.imgHeight, this.newFile);
}
拓展
UI定制
一些按鈕、滑塊等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();
}
}
保持相對繪制路徑
為了獲得更大的繪制區(qū)域,所以繪制面積并非為圖片顯示區(qū)域,這也就導致了旋轉(zhuǎn)的時候,相對位置會有變化。如果你需要保持相對,可以控制繪制區(qū)域與圖片顯示區(qū)域保持一致即可。
參考及其他文章
地址
github倉庫地址: image_editor_dove
插件地址:image_editor_dove
參考插件
signature | Flutter Package (flutter-io.cn)
到此這篇關(guān)于Flutter簡潔實用的圖片編輯器的實現(xiàn)的文章就介紹到這了,更多相關(guān)Flutter 圖片編輯器內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Android使用SQLite數(shù)據(jù)庫的簡單實例
這篇文章主要介紹了Android使用SQLite數(shù)據(jù)庫的簡單實例,有需要的朋友可以參考一下2013-12-12
Android中使用listview實現(xiàn)qq/微信好友列表
本文主要介紹了android中使用listview實現(xiàn)qq/微信好友列表(頭像,昵稱,個性簽名)的相關(guān)知識。具有很好的參考價值。下面跟著小編一起來看下吧2017-04-04
使用Flutter 構(gòu)建Web應(yīng)用邏輯解析
這篇文章主要為大家介紹了使用Flutter 構(gòu)建Web應(yīng)用邏輯解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-12-12
Android usb設(shè)備權(quán)限查詢及自動獲取詳解流程
本篇文章介紹了我想要獲取Android系統(tǒng)usb設(shè)備使用權(quán)限時遇到的問題,以及解決該問題的過程及思路,通讀本篇對大家的學習或工作具有一定的價值,需要的朋友可以參考下2021-10-10

