Flutter 之简洁实用的图片编辑器

49 篇文章 0 订阅
47 篇文章 0 订阅

介绍

一款简洁实用的图片编辑器,纯dart开发。支持:涂鸦、旋转&翻转、马赛克、添加文字,及自定义ui风格。

功能演示

涂鸦

draw.gif

旋转&翻转

flip&rotate.gif

马赛克

mosaic.gif

添加文字及删除

text_delete.gif

addtext_done.gif

安装

添加依赖

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

拓展

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

保持相对绘制路径

为了获得更大的绘制区域,所以绘制面积并非为图片显示区域,这也就导致了旋转的时候,相对位置会有变化。如果你需要保持相对,可以控制绘制区域与图片显示区域保持一致即可。

参考及其他文章

地址

github仓库地址: image_editor_dove

插件地址:image_editor_dove

参考插件

signature | Flutter Package (flutter-io.cn)

其他文章

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值