搜索插件、代码仓与 APP 分类

插件详情v0.0.6

image_crop_widget

一个用于裁剪图像的 Flutter 小部件。该小部件完全用 Dart 编写,依赖项极少。

近 30 天下载
28
喜欢数
9
Pub 分数
40

安装插件

flutter pub add image_crop_widget

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个专为在应用内直接裁剪图像而设计的 Flutter 小部件。完全使用 Dart 编写,依赖极少,提供轻量且高效的图像处理解决方案。该小部件提供了直观的控制功能,用于选择和调整裁剪区域,非常适合用于头像编辑或图像预处理。它可无缝集成到 Flutter 项目中,并支持不同屏幕尺寸的响应式设计。

适合场景

  • 个人资料图片裁剪
  • 上传前的图像预处理
  • 用户生成内容编辑
  • 应用中的照片编辑工具
  • 自定义图像选择工作流

主要特点

  • 纯 Dart 实现
  • 最小依赖
  • 响应式用户界面
  • 直观的拖放裁剪控件
  • 与 Flutter 项目的轻松集成

适合对象

  • 开发图像密集型应用的开发者
  • 需要用户图像裁剪的应用
  • 优先考虑轻量级依赖项的项目
  • 前端开发人员寻求简单解决方案
  • 移动应用功能,带有图像编辑需求

使用建议

  • 仅限基本裁剪功能
  • 无内置图像滤镜或增强功能
  • 需要手动处理裁剪后的图像输出
  • 未针对非常大的图像进行优化
  • 不支持同时多个裁剪区域

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

image_crop_widget

A Flutter widget to crop images. The widget is completely written in Dart and has minimal dependencies.

The widget displays the image within the given layout space. On top of the image a transparent rectangular overlay, with handles on each corner, is drawn. The overlay handles can be dragged by touch to adjust the cropping area.

Example

By calling the cropImage() method on the widget's state object, the image area that is marked by the overlay is returned as a new image object.

To acquire the widget's state you can use a GlobalKey object.

Example:

import 'dart:ui'; // This imports the 'Image' class.

final key = GlobalKey<ImageCropState>();
Image imageObject = ...

...

ImageCrop(key: key, image: imageObject) // This could be used inside a  build method.

...
await key.currentState.rotateImage(); // Rotate the image be 90° clockwise.
final cropedImage = await key.currentState.cropImage(); // This could be used inside a 'onPress' handler method.

How to create an image object

The Image class from dart:ui is typically not instantiated directly. Instead, you could convert your image data into a Uint8List and instantiate the image like this:

Uint8List bytes = ...
final codec = await instantiateImageCodec(bytes);
final frame = await codec.getNextFrame();
final image = frame.image;

How to display an image object

The Image object can be displayed with the Flutter Image widget. One way to do this, is by converting the image into a Uint8List and pass it into the widget's memory constructor. Please note, that the widget is not the same Image class as the image object itself.

final cropedImage = await key.currentState.cropImage();
final byte = await cropedImage.toByteData(format: ui.ImageByteFormat.png);
final byteList = byte.buffer.asUint8List();

Image.memory(byteList)

How to persist an image object

The Image object can be persisted into a file or a database. To do this, you can convert the image object into a Uint8List and write it into a File or your database object.

final cropedImage = await key.currentState.cropImage();
final byte = await cropedImage.toByteData(format: ui.ImageByteFormat.png);
final byteList = byte.buffer.asUint8List();

final imageFile = File("Some path and filename"); // You can use the path_provider package to locate the right path.
final result = await imageFile.writeAsBytes(byteList);

所属分类

源码仓库

使用此插件的项目

暂无相关数据。