Flutter package for painting on images

Overview

image_painter

pub package style: effective dart Platform Badge License: MIT

A flutter implementation of painting over image.

Overview

demo!

Features

  • Seven available paint modes. Line, Box/Rectangle, Circle, Freestyle/Signature, Dotted Line, Arrow and Text.
  • Four constructors for adding image from Network Url, Asset Image, Image from file and from memory.
  • Controls from constructors like strokeWidth and Colors.
  • Export image as memory bytes which can be converted to image. Implementation provided on example
  • Ability to undo and clear drawings.

[Note] Tested and working only on flutter stable channel. Please make sure you are on stable channel of flutter before using the package.

Getting started

In the pubspec.yaml of your flutter project, add the following dependency:

dependencies:
  ...
  image_painter: latest

In your library add the following import:

import 'package:image_painter/image_painter.dart';

For help getting started with Flutter, view the online documentation.

Using the library

Check out the example

Basic usage of the libary:

  • ImagePainter.network: Painting over image from network url.
final _imageKey = GlobalKey<ImagePainterState>();
//Provide controller to the painter.
ImagePainter.network("https://sample_image.png",
                  key: _imageKey,scalable: true),

///Export the image:
Uint8List byteArray = await _imageKey.currentState.exportImage();
//Now you use `Uint8List` data and convert it to file.
File imgFile = new File('directoryPath/fileName.png');
imgFile.writeAsBytesSync(image);

For more thorough implementation guide, check the example.

Comments
  • Null Safety on exportImage

    Null Safety on exportImage

    Thanks for this library, and starting to migrate it to null safety.

    I am using image_painter: ^1.0.0-nullsafety.0.

    My project is set with:

    environment:
      sdk: ">=2.12.0 <3.0.0"
    

    As I was implementing image_painter in my project, I was having issues with exportImage.

    It kept complaining about ByteData, and then buffer. Eventually I hit upon this combination:

      ///Generates [Uint8List] of the [ui.Image] generated by the [renderImage()] method.
      ///Can be converted to image file by writing as bytes.
      Future<Uint8List?> exportImage() async {
        ui.Image _image;
        if (widget.isSignature) {
          final _boundary = _repaintKey.currentContext!.findRenderObject()
              as RenderRepaintBoundary;
          _image = await _boundary.toImage(pixelRatio: 3);
        } else if (widget.byteArray != null && _paintHistory.isEmpty) {
          return widget.byteArray;
        } else {
          _image = await _renderImage();
        }
        final byteData = await (_image.toByteData(format: ui.ImageByteFormat.png) as FutureOr<ByteData?>);
        return byteData?.buffer.asUint8List();
    

    Note the last 2 lines, specifically.

    I don't know if it's correct or not, but thought I'd pass it along in case it helps.

    I'm still learning, very slowly, so it's certainly possible this could be done better.

    work in progress 
    opened by ccc-dvansevenant 10
  • Added

    Added "controlsBackgroundColor" and fixed the Android example

    So first of all i'm sorry if i'm doing something wrong, it's my first time on contributing to a repo but i'm willing to help or do anything to make this easier.

    About the changes, i added the field "controlsBackgroundColor" to all of the constructors, a simple thing but if this goes well i'm planning on keep contributing to this repo, i would really appreciate any advice.

    Also i made another example, it just loads an image for editing using image_picker package, there were a lot of problems about migration but i think is fixed now. The example is just a full screen button that shows a ImagePicker, then a ImagePainter allows editing. The black background color was achieved by simple using a Stack, where the bottom buttons are also placed.

    341b19a0-1987-4046-a609-56ea81c95992 7d2dd726-9a1c-463b-9162-3f58751b5543 (1)

    opened by SmearyQuill 3
  • Undo is not working when zooming in/out

    Undo is not working when zooming in/out

    Can't undo changes when drawing, and after interacting with "view/zoom" option from menu. This could be a state problem, i can't find how to solve it.

    opened by nekomaruh 2
  • "Erase All" has the same tooltip as "undo"

    In "_paint_over_image.dart" consider updating this:

    IconButton(
                tooltip: **textDelegate.undo**,
                icon: widget.clearAllIcon ??
                    const Icon(CommunityMaterialIcons.eraser),
                onPressed: () => setState(_paintHistory.clear),
              ),
    

    To this:

    IconButton(
                tooltip: **textDelegate.clearAllProgress**,
                icon: widget.clearAllIcon ??
                    const Icon(CommunityMaterialIcons.eraser),
                onPressed: () => setState(_paintHistory.clear),
              ),
    

    I forked this project and i love it, thumbs up to the creator!!

    opened by nekomaruh 2
  • Image Painter Network Constructor does not setup value for scalable

    Image Painter Network Constructor does not setup value for scalable

    Image Painter network constructor does not setup value for attribute isScalable. This causes issues with ImagePainterTransformer because isScalable has a null assertion.

    image image

    opened by NahuelBiladoniga 2
  • how to reverse painting for free style?

    how to reverse painting for free style?

    How to painting and then reverse the painting area . It just like put a full layer top the image, then using finger smearing the area user want to keep, after that, user will only to keep the area they want [the smeared area]

    image

    For the example, user really want to keep the area what the smeared by red color,

    feature not in plan 
    opened by cnmade 1
  • SCROLLING ISSUE

    SCROLLING ISSUE

    Hi,

    I have an issue in scrolling while using this widget in my project. It all worked fine but when I start dragging it using mouse, it scrolls the whole screen. Please check the attached git. I am also using the other package for signatures and there is no issue in that one and it worked all fine but this one is not working fine.

    https://user-images.githubusercontent.com/72092249/139265428-fde52bea-0764-45e9-bc0f-dbbb1807eb7f.mov

    opened by truly6ve 1
  • PaintMode text does not work

    PaintMode text does not work

    Problem

    The dropdown of PaintMode includes text. If text is selected nothing happens. This mode is redundant because the text mode already exists in the action bar next to the stroke size selection.

    Following this it would be nice to activate or deactivate features of the action bar and to restrict selection of the aviable paint modes.

    opened by ynnob 1
  • Feature request: Set initial PaintMode

    Feature request: Set initial PaintMode

    We would like to set the initial paint mode. Currently line is the default when opening the widget with an Image File. We would like to set the PaintMode to freeStyle.

    Our current implementation and call of the ImagePainter looks like this:

    ImagePainter.file(
              File(widget.imagePath),
              key: _imageKey,
              scalable: true,
            )
    

    Is there a way to manipulate the controller in any way? Or should we fork this projekt to customize it further?

    Thank you!

    work in progress 
    opened by ynnob 1
  • Scaling mode is not preventing draw mode

    Scaling mode is not preventing draw mode

    Problem

    If the mode scalable is set to true the ImagePainter does not prevent painting while scaling. Also this mode should be called zoom instead of scaling because the scaling of the image is not saved.

    Solution

    Implement a Listener wrapped around the canvas that handles the current FingerCount:

    [...] Listener(
          onPointerDown: (_) => increaseFingerCount(),
          onPointerUp: (_) => decreaseFingerCount(),
          child: [...]
    

    Then cancel painting when the fingerCount is == 2

    if (_fingerCount == 2) {
       return;
    }
    
    opened by ynnob 1
  • Extraction of paint layers

    Extraction of paint layers

    Hi thanks for the cool lib.

    I was wondering if it is possible to return just the paint layer seperate from the image.. I have tried: original_img - painted_img however this doesn't seem to work (perhaps some postprocessing that changes resolution / pixels values subtely?)

    Thanks

    opened by torphix 0
  • Hi, is there a way to change the zoom behaviour?

    Hi, is there a way to change the zoom behaviour?

    When a horizontal image is loaded to the painter the image is really tinny, and when zoomed it doesn't changes it size, the zoom remains inside the area of the image.

    Is there a way to change this behavior so the image scales using all the available space, maybe adding a new paint mode to allow crop?

    thank you.

    opened by SmearyQuill 1
  • Add the ability to rotate the painted figures

    Add the ability to rotate the painted figures

    It would be nice to see some sort of control to rotate a painted figure, from other apps rotating can be quite frustrating but maybe a special icon placen on the edge of a selected figure could simplify that process

    opened by SmearyQuill 1
Owner
yellowQ
Field Service Software
yellowQ
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
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 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

101Loop 12 Sep 26, 2022
A Flutter package which provides 360 view of the images with rotation and gesture customisations.

imageview360 A Flutter package which provides 360 view of the images with rotation and gesture customisations. Supported Dart Versions Dart SDK versio

hd-motion 104 Dec 1, 2022
Flutter package to share images on social media

social_share Wide variety of sharing options you'll need to share directly to certain popular apps or just share with default native share. Introducti

Shekar Mudaliyar 74 Dec 8, 2022
Stories like in Instagram, each story can include multiple images and videos. Package supports video, titles, preliminary caching.

flutter_instagram_stories A Flutter package for displaying stories just like Whatsapp & Instagram. Built-in groups (multiple stories with one icon), c

Alex Awaik 125 Dec 9, 2022
A simple web API to generate images from a url, made using shelf package.

Webshot API Yet another simple webshot API but written in dart and built using Shelf library to generate images from url. This is really useful for li

wrench 15 Oct 19, 2022
Aq flutter tools - AQ flutter tools - Responsive Images, Translations and more

Made by AQuadic Getting started Important Links AQuadic Script Requirement This

Aquadic 0 Feb 7, 2022
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

Johannes Milke 28 Dec 4, 2022
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

Johannes Milke 30 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.

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

Weta Vietnam 91 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

Carnegie Technologies 131 Nov 25, 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 simple Flutter app showing cat images from CatApi

CAT APP A simple Flutter app showing cat images from CatApi USE Bloc REST API St

null 0 Jan 10, 2022
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
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
A Flutter widget to crop images.

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

Florian Bauer 11 Nov 29, 2022
Flutterbodydetection - A flutter plugin that uses MLKit on iOS/Android platforms to enable body pose and mask detection using Pose Detection and Selfie Segmentation APIs for both static images and live camera stream.

body_detection A flutter plugin that uses MLKit on iOS/Android platforms to enable body pose and mask detection using Pose Detection and Selfie Segmen

null 18 Dec 5, 2022