溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

如何實(shí)現(xiàn)Flutter簡(jiǎn)潔實(shí)用的圖片編輯器

發(fā)布時(shí)間:2022-02-11 09:13:30 來源:億速云 閱讀:410 作者:小新 欄目:開發(fā)技術(shù)

小編給大家分享一下如何實(shí)現(xiàn)Flutter簡(jiǎn)潔實(shí)用的圖片編輯器,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

介紹

一款簡(jiǎn)潔實(shí)用的圖片編輯器,純dart開發(fā)。支持:涂鴉、旋轉(zhuǎn)&翻轉(zhuǎn)、馬賽克、添加文字,及自定義ui風(fēng)格。

功能演示

涂鴉

如何實(shí)現(xiàn)Flutter簡(jiǎn)潔實(shí)用的圖片編輯器

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

如何實(shí)現(xiàn)Flutter簡(jiǎn)潔實(shí)用的圖片編輯器

馬賽克

如何實(shí)現(xiàn)Flutter簡(jiǎn)潔實(shí)用的圖片編輯器

添加文字及刪除

如何實(shí)現(xiàn)Flutter簡(jiǎn)潔實(shí)用的圖片編輯器

如何實(shí)現(xiàn)Flutter簡(jiǎn)潔實(shí)用的圖片編輯器

安裝

添加依賴

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,
        //可空,支持自定義存儲(chǔ)位置(編輯后的圖片)
        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風(fēng)格:

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();
  }
}

保持相對(duì)繪制路徑

為了獲得更大的繪制區(qū)域,所以繪制面積并非為圖片顯示區(qū)域,這也就導(dǎo)致了旋轉(zhuǎn)的時(shí)候,相對(duì)位置會(huì)有變化。如果你需要保持相對(duì),可以控制繪制區(qū)域與圖片顯示區(qū)域保持一致即可。

以上是“如何實(shí)現(xiàn)Flutter簡(jiǎn)潔實(shí)用的圖片編輯器”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI