A Flutter widget to crop images.

Overview

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);
You might also like...

A customizable toggle switch widget to add asset background images to the toggle switch.

A customizable toggle switch widget to add asset background images to the toggle switch.

A customizable toggle switch widget to add asset background images to the toggle switch. Features Use this package to give fancy background images to

Jul 26, 2022

Widget to count the amount of nested widget tree, useful in the dynamic construction of the interface when it is important to know the depth of widget.

Widget to count the amount of nested widget tree, useful in the dynamic construction of the interface when it is important to know the depth of widget.

widget_tree_depth_counter Widget Tree Depth Counter WidgetTreeDepthCounter is a simple widget to count the amount of nested widget tree, useful in the

Aug 1, 2022

Aq flutter tools - AQ flutter tools - Responsive Images, Translations and more

Aq flutter tools - AQ flutter tools - Responsive Images, Translations and more

Made by AQuadic Getting started Important Links AQuadic Script Requirement This

Feb 7, 2022

Download files from Firebase Storage with Flutter. List all images, videos, or other files from Firebase and download them.

Download files from Firebase Storage with Flutter. List all images, videos, or other files from Firebase and download them.

Flutter Tutorial - Download Files From Firebase Storage Download files from Firebase Storage with Flutter. List all images, videos, or other files fro

Dec 4, 2022

Upload Files To Firebase Storage with Flutter. Pick images, videos, or other files from your device and upload them to Firebase.

Upload Files To Firebase Storage with Flutter. Pick images, videos, or other files from your device and upload them to Firebase.

Flutter Tutorial - Upload Files To Firebase Storage Upload Files To Firebase Storage with Flutter. Pick images, videos, or other files from your devic

Dec 28, 2022

Flutter plugin for selecting images from the Android and iOS image library, taking new pictures with the camera, and edit them before using such as rotation, cropping, adding sticker/text/filters.

Flutter plugin for selecting images from the Android and iOS image library, taking new pictures with the camera, and edit them before using such as rotation, cropping, adding sticker/text/filters.

advance_image_picker Flutter plugin for selecting multiple images from the Android and iOS image library, taking new pictures with the camera, and edi

Dec 19, 2022

Flutter plugin that saves images and videos to devices gallery

Gallery Saver for Flutter Saves images and videos from network or temporary file to external storage. Both images and videos will be visible in Androi

Nov 25, 2022

A Flutter package providing an easy way to add floating ribbon to images.

A Flutter package providing an easy way to add floating ribbon to images.

Floating Ribbon A new Flutter package for creating floating ribbons on images. Dependency dependencies: floating_ribbon: any How To Use In order to

Sep 26, 2022
Comments
  • Unsupported operation: _Namespace

    Unsupported operation: _Namespace

    I am having this error: Unsupported operation: _Namespace

    At this line:

    ui.Image croppedImage = await key.currentState.cropImage();

    This is occurring in Flutter Web.

    opened by pulstar 3
  • Invert the background & contrast handles to make crop handles more visible.

    Invert the background & contrast handles to make crop handles more visible.

    Hey, great package!

    One request though: as handles stand, they can be difficult (and sometimes impossible) to see when cropping light images or images with white backgrounds (such as memes and and grid comics).

    I'd like to suggest inverting the background so that the crop area itself is clear, and the area around it is dimmed. Also, adding a stroke to the border of the crop area should make it more visible, to contrast a possible light background. See before and after below.

    Before: image

    I've made the changes in a fork, here: image

    If you agree with these suggestions, I'm happy to make any changes to my fork and open a PR. If not then I'm also happy to publish my fork as an alternative to your package.

    Other than that, I just want to say great package, really. I've tried 2-3 cropping packages and none of them had everything I needed. This one did, super simple!

    opened by fadulalla 2
  • Support for Flutter Web?

    Support for Flutter Web?

    Hey,

    is there an implementation for flutter web planned as well? On pub.dev it said that web is supported, however, I tried it and it did not work.

    Thanks! :)

    opened by ghost 1
  • [Request] Bigger corner regions and movable crop area

    [Request] Bigger corner regions and movable crop area

    First of all - thank you VERY much! While this cropper is missing good UI, it's still much better than the current libraries with their clumsy and annoying controls.

    But you're still missing a few essential features:
    1. The detection radius of the corners is small and the user often misses them, which gives a laggy impression. So it would be great if we could pass a parameter that would control the size of the corner dots or simply the radius of the detection area. 2. Crop area should be movable. Current libraries implement this feature by moving the image while keeping the crop area fixed at the center of the screen (which is extremely annoying). Could you make it so that image always remains fixed and it's the crop area which is moving? Ideally, you could implement both modes and add a boolean parameter which would choose the mode.

    All in all, this library has great potential (many thanks for that), but, personally, I'll be sticking to platform-specific crop libraries until this gets a few updates. Going to follow with interest. Thanks again!

    enhancement 
    opened by Gyoko 3
Owner
Florian Bauer
Florian Bauer
Flutter plugin, support android/ios.Support crop, flip, rotate, color martix, mix image, add text. merge multi images.

image_editor The version of readme pub and github may be inconsistent, please refer to github. Use native(objc,kotlin) code to handle image data, it i

FlutterCandies 317 Jan 3, 2023
Display images flutter - Simple app to display images in flutter

Display Images In Flutter Simple app to display images in a flutter. In this dem

Manish Ahire 1 Jan 29, 2022
In this repo you will see how to pick images from the image library and also, see how to store the selected images on Firebase.

flutterimageapp Flutter Tutorial - Upload Images using Firebase Storage. Flutter Tutorial - Upload Images using Firebase Storage Video series can be w

Whatsupcoders 60 Nov 4, 2022
camilo velandia 69 Dec 30, 2022
Memebaaz is a video/images sharing app, Anyone can share short videos and images through app, the media will go through admin's approval.

MemeBaaz - Memes & Short Videos App Memebaaz is a Video/images Sharing App, Anyone can share short videos and images through app, the media will go th

Rakesh K. 18 Nov 14, 2022
A flutter plugin to crop image on iOS and Android.

Image Cropping plugin for Flutter A flutter plugin to crop image on iOS and Android. The plugin comes with a Crop widget. The widget renders only imag

Volodymyr Lykhonis 292 Dec 27, 2022
FLUTTER API: Video Editor allows trim, crop, rotate and scale video with a super flexible UI Design

video_editor My other APIs Scroll Navigation Video Viewer Helpers Features Super flexible UI Design. Support actions: Crop Trim Scale Rotate Cover sel

Luis Felipe Murguia Ramos 214 Dec 26, 2022
This is a flutter plugin to detect edges in a live camera, take the picture of detected edges object, crop it, and save.

edge_detection A flutter plugin to detect edges of objects, scan paper, detect corners, detect rectangles. It allows cropping of the detected object i

Sawan Kumar Bundelkhandi 180 Dec 28, 2022
Picture upload widget for Flutter which helps selecting and uploading one or multiple images to firebase storage.

Flutter Firebase Picture Uploader This library offers a Picture Upload widget which can be used to upload one or multiple images to your Firebase Stor

Christoph Rothermel 12 Oct 21, 2022
A Flutter widget for images sliding

Simple Image Slider Widget (https://pub.dartlang.org/packages/simple_slider) A flutter library to show images in a sliding widget, the library also pr

Eddy WM 53 Jul 20, 2022