Giter Site home page Giter Site logo

fluttercandies / flutter_image_editor Goto Github PK

View Code? Open in Web Editor NEW
392.0 6.0 122.0 3.27 MB

Flutter plugin, support android/ios.Support crop, flip, rotate, color martix, mix image, add text. merge multi images.

License: Apache License 2.0

Kotlin 12.02% Ruby 3.45% Swift 0.99% Objective-C 35.35% Dart 43.14% Java 0.50% Shell 1.42% TypeScript 1.78% Batchfile 1.02% Python 0.33%
crop flip image flutter plugin rotate android ios edit editor dart

flutter_image_editor's Introduction

image_editor

BUILD

The version of readme pub and github may be inconsistent, please refer to github.

Use native(objc,kotlin,arkts) code to handle image data, it is easy to process pictures, and can be used for saving/uploading/preview images.

Screenshot

img

Platform of support

Android, iOS, OpenHarmony

OpenHarmony 平台的例子,请运行 image_editor_ohos/example

Change Log

This version is a null-safety version.

Please read document for null-safety information in dart or flutter.

Support

Feature Android iOS OpenHarmony
flip
crop
rotate
scale
matrix
mix image
merge multi image
draw point
draw line
draw rect
draw circle
draw path
draw Bezier
Gaussian blur

ImageEditor Usage

pub package GitHub GitHub stars

dependencies:
  image_editor: $latest

About version, please find it from pub.

Import

import 'package:image_editor/image_editor.dart';

Method list:

ImageEditor.editImage();
ImageEditor.editFileImage();
ImageEditor.editFileImageAndGetFile();
ImageEditor.editImageAndGetFile();

Example used alone

Example of extended_image

ImageEditor method params

Name Description
image dart.typed_data.Uint8List
file dart.io.File
imageEditorOption flutter_image_editor.ImageEditorOption

ImageEditorOption

final editorOption = ImageEditorOption();
editorOption.addOption(FlipOption());
editorOption.addOption(ClipOption());
editorOption.addOption(RotateOption());
editorOption.addOption(); // and other option.

editorOption.outputFormat = OutputFormat.png(88);

Option

Flip

FlipOption(horizontal:true, vertical:false);

Clip

ClipOption(x:0, y:0, width:1920, height:1920);

Rotate

RotateOption(degree: 180);

Color Martix

ColorOption();

it's use 5x4 matrix : https://developer.android.google.cn/reference/android/graphics/ColorMatrix.html Although it is an Android document, the color matrix is also applicable to iOS.

a, b, c, d, e,
f, g, h, i, j,
k, l, m, n, o,
p, q, r, s, t

ColorOption has some factory constructor to help use change brightness, saturation and contrast. If you have more color matrix, you can open Pull Requests or issue.

Scale

ScaleOption(width, height, keepRatio: keepRatio, keepWidthFirst: keepWidthFirst);

keepRatio and keepWidthFirst are optional parameters used to maintain the aspect ratio of the original image to prevent image deformation.

keepWidthFirst takes effect only when keepRatio is true.

The following is a brief description:

width height keepRatio keepWidthFirst src size dest size
500 300 false true/false 1920x1920 500x300
500 300 true true 1920x1920 500x500
500 300 true false 1920x1920 300x300

AddText

All of unit is pixel.

final textOption = AddTextOption();
textOption.addText(
  EditorText(
    offset: Offset(0, 0),
    text: this._controller.text,
    fontSizePx: size,
    color: Colors.red,
    fontName: '', // You must register font before use. If the fontName is empty string, the text will use default system font.
  ),
);
FontManager

Here we can use FontManager to register font.

File fontFile = File(path)//;
final String fontName = await FontManager.registerFont(fontFile);

// The fontName can be use in EditorText.
// If you want to use system font, you can use empty string.
final textOption = AddTextOption();
textOption.addText(
  EditorText(
    offset: Offset(0, 0),
    text: this._controller.text,
    fontSizePx: size,
    color: Colors.red,
    fontName: fontName, // You must register font before use.
  ),
);

MixImage

void mix(BlendMode blendMode) async {
  final src = await loadFromAsset(R.ASSETS_SRC_PNG);
  final dst = await loadFromAsset(R.ASSETS_DST_PNG);
  final optionGroup = ImageEditorOption();
  optionGroup.outputFormat = OutputFormat.png();
  optionGroup.addOption(
    MixImageOption(
      x: 300,
      y: 300,
      width: 150,
      height: 150,
      target: MemoryImageSource(src),
      blendMode: blendMode,
    ),
  );
  final result =
      await ImageEditor.editImage(image: dst, imageEditorOption: optionGroup);
  this.image = MemoryImage(result);
  setState(() {});
}
BlendMode

Support next BlendMode, other will be ignored. You can also see the document of flutter.

iOS/macOS android(PorterDuff.Mode) flutter(BlendMode)
kCGBlendModeClear CLEAR clear
SRC src
DST dst
kCGBlendModeNormal SRC_OVER srcOver
kCGBlendModeDestinationOver DST_OVER dstOver
kCGBlendModeSourceIn SRC_IN srcIn
kCGBlendModeDestinationIn DST_IN dstIn
kCGBlendModeSourceOut SRC_OUT srcOut
kCGBlendModeDestinationOver DST_OUT dstOut
kCGBlendModeSourceAtop SRC_ATOP srcATop
kCGBlendModeDestinationAtop DST_ATOP dstATop
kCGBlendModeXOR XOR xor
kCGBlendModeDarken DARKEN darken
kCGBlendModeLighten LIGHTEN lighten
kCGBlendModeMultiply MULTIPLY multiply
kCGBlendModeScreen SCREEN screen
kCGBlendModeOverlay OVERLAY overlay

DrawOption

Main class : DrawOption

Support:

  • Line
  • Rect
  • Oval
  • Points
  • Path
    • move
    • line
    • bezier2
    • bezier3

Example

Style of paint: DrawPaint, user can set lineWeight,color,style(stroke,fill).

OutputFormat

var outputFormat = OutputFormat.png();
var outputFormat = OutputFormat.jpeg(95); // The 95 is quality of jpeg.

ImageMerge

    final slideLength = 180.0;
    final option = ImageMergeOption(
      canvasSize: Size(slideLength * count, slideLength * count),
      format: OutputFormat.png(),
    );

    final memory = await loadFromAsset(R.ASSETS_ICON_PNG);
    for (var i = 0; i < count; i++) {
      option.addImage(
        MergeImageConfig(
          image: MemoryImageSource(memory),
          position: ImagePosition(
            Offset(slideLength * i, slideLength * i),
            Size.square(slideLength),
          ),
        ),
      );
    }
    for (var i = 0; i < count; i++) {
      option.addImage(
        MergeImageConfig(
          image: MemoryImageSource(memory),
          position: ImagePosition(
            Offset(
                slideLength * count - slideLength * (i + 1), slideLength * i),
            Size.square(slideLength),
          ),
        ),
      );
    }

    final result = await ImageMerger.mergeToMemory(option: option);
    provider = MemoryImage(result);
    setState(() {});

LICENSE

Apache License 2.0

Third party

Under Apache 2.0 style:

Some martix code come from android sdk.

TrueTypeParser : Use it to read font name.

flutter_image_editor's People

Contributors

alexv525 avatar bcse avatar caijinglong avatar ccadieux avatar grubesa avatar jacob-hutchings avatar kreativityapps avatar magtuxgit avatar paricleu avatar ramtinq avatar reynirf avatar ruerob avatar zmtzawqlp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

flutter_image_editor's Issues

Major error occurs when trying to access the rawImageData

There is following issue.
As a default within the ExtendedImage.file the cropAspectRatio is ratio9_16. (screenshot 1)
Screenshot 2021-04-19 at 10 05 14

When the user switches to the ratio CropAspectRatios.original everything works fine (see screenshot 2)
Screenshot 2021-04-19 at 10 04 43

Now when I try to crop the image to the 9_16 format I run the cropImageDataWithNativeLibrary.
This now throws me following error: Unhandled Exception: 'package:extended_image_library/src/extended_image_provider.dart': Failed assertion: line 38 pos 7: 'rawImageDataMap.containsKey(this)': raw image data is not already now! and stack: #0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:46:39)

Entire error stack:
flutter: native library start cropping [ +7 ms] [VERBOSE-2:ui_dart_state.cc(186)] Unhandled Exception: 'package:extended_image_library/src/extended_image_provider.dart': Failed assertion: line 38 pos 7: 'rawImageDataMap.containsKey(this)': raw image data is not already now! and stack: #0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:46:39) [ ] #1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:36:5) [ ] #2 ExtendedImageProvider.rawImageData (package:extended_image_library/src/extended_image_provider.dart:38:7) [ ] #3 ExtendedImageEditorState.rawImageData (package:extended_image/src/editor/extended_image_editor.dart:307:34) [ ] #4 ImageEditorService.cropImageDataWithNativeLibrary (package:dayblizz/core/services/ui/image_editor_service.dart:35:33) [ ] #5 SelectImageProvider._cropImage (package:dayblizz/core/viewmodels/upload/select_Image_Provider.dart:311:12) [ ] #6 SelectImageProvider._replaceSelectedImageWithCroppedImage (package:dayblizz/core/viewmodels/upload/select_Image_Provider.dart:281:35) [ ] #7 SelectImageProvider.navigateToNextScreen (package:dayblizz/core/viewmodels/upload/select_Image_Provider.dart:347:11) [ ] #8 SelectImageScreen.build.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:dayblizz/ui/screens/Upload/select_Image_Screen.dart:104:50) [ ] #9 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24) [ ] #10 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:607:11) [ ] #11 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:296:5) [ ] #12 BaseTapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:267:7) [ ] #13 GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:157:27) [ ] #14 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:385:20) [ ] #15 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:361:22) [ ] #16 RendererBinding.dispatchEvent (package:flutter/src/rendering/binding.dart:278:11) [ ] #17 GestureBinding._handlePointerEventImmediately (package:flutter/src/gestures/binding.dart:316:7) [ ] #18 GestureBinding.handlePointerEvent (package:flutter/src/gestures/binding.dart:280:5) [ ] #19 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:238:7) [ ] #20 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:221:7) [ ] #21 _rootRunUnary (dart:async/zone.dart:1370:13) [ ] #22 _CustomZone.runUnary (dart:async/zone.dart:1265:19) [ ] #23 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1170:7) [ ] #24 _invoke1 (dart:ui/hooks.dart:180:10) [ ] #25 PlatformDispatcher._dispatchPointerDataPacket (dart:ui/platform_dispatcher.dart:276:7) [ ] #26 _dispatchPointerDataPacket (dart:ui/hooks.dart:96:31) [ ] #0 SelectImageProvider._cropImage (package:dayblizz/core/viewmodels/upload/select_Image_Provider.dart:315:7) [ ] <asynchronous suspension> [ ] #1 SelectImageProvider._replaceSelectedImageWithCroppedImage (package:dayblizz/core/viewmodels/upload/select_Image_Provider.dart:281:29) [ ] <asynchronous suspension> [ ] #2 SelectImageProvider.navigateToNextScreen (package:dayblizz/core/viewmodels/upload/select_Image_Provider.dart:347:5) [ ] <asynchronous suspension>

Screenshot 2021-04-19 at 10 06 49

Error occuring screenshot:
Screenshot 2021-04-19 at 10 22 09

Funny fact, if I don't change the aspect Ratio of the image there is of course no cropping and therefore there is also no error.

My question now is, what does this error mean ( 'rawImageDataMap.containsKey(this)': raw image data is not already now! and stack)?
This error occured since this cache mechnism has been included.

Android EditImage ClipOption not supported zoom image

While zoom the image to a larger proportion, crop image error, a platform exception thrown. (iOS is ok)
Error info
image

Could crop image:
IMG_1877

Could not crop image:
IMG_1876

code:

 final editOptions = ImageEditorOption();

      editOptions.addOption(
        ClipOption.fromRect(
          imageToCrop.cropSection,
        ),
      );

      editOptions.addOption(
        ScaleOption(570, 570),
      );

      editOptions.addOption(
        ClipOption(width: 500, height: 500),
        newGroup: true,
      );

      final croppedImage = await ImageEditor.editImage(
        image: imageToCrop.imageBytes,
        imageEditorOption: editOptions,
      );

Temp File Path is wrong

 static Future<String> _createTmpFilePath() async {
    final cacheDir = await NativeChannel.getCachePath();
    final name = DateTime.now().millisecondsSinceEpoch;
    return "$cacheDir/$name";
  }

"$cacheDir/$name" = "Directory: '/data/user/0/com.sample.debug/cache'1577749314116"

your NativeChannel.getCachePath(); returns Directory instance not a String

solution
return "${cacheDir.path}/$name";

Adding Multiple Images

How can we add multiple images onto a canvas and then be able to drag them around, in a canvas or a screen?

Documentation for EditorText.

EditorText( offset: const Offset(79.1, 201.8), text: _controller.text, fontSizePx: size, textColor: const Color(0xFF995555), fontName: fontName, ),

i tried localPosition as well as the globalPosition in the offset but it seems to place somewhere else. How to preemptively calculate the offset to place text in required position in the image

cropAspectRatio changes after rotate

I want to crop photo with AspectRatio 3/4 and give to user an opportunity to rotate photo.
But after rotation AspectRatio become 4/3.
Is there any way to fix it?

MissingPluginException memoryToMemory for web

It seems that no native code has been implemented for web.

I got following exception:

MissingPluginException(No implementation found for method memoryToMemory on channel top.kikt/flutter_image_editor)

Here is my code

    var action = state.editAction;

    ///crop rect base on raw image
    final Rect? rect = state.getCropRect();
    final rotateAngle = action?.rotateAngle.toInt();
    final flipHorizontal = action?.flipY;
    final flipVertical = action?.flipX;
    final img = state.rawImageData;

    ImageEditorOption option = ImageEditorOption();

    if (action!.needCrop) option.addOption(ClipOption.fromRect(rect!));

    if (action.needFlip)
      option.addOption(
          FlipOption(horizontal: flipHorizontal!, vertical: flipVertical!));

    if (action.hasRotateAngle) option.addOption(RotateOption(rotateAngle!));
    option.outputFormat = OutputFormat.png(88);

    final result = await ImageEditor.editImage(
      image: img,
      imageEditorOption: option,
    );

    return result;
  }

Null safety

This is a request to add support for null safety to this package. See the migration guide for details about enabling null safety.

(OS Error: Permission denied, errno = 13).

I cannot upload/load image from gallery and external storage. This is my logcat
FileSystemException: Cannot open file, path = '/storage/emulated/0/DCIM/s9camera/Pic_2020_06_04_19_36_15.jpg' (OS Error: Permission denied, errno = 13).
Android - 29
I'm using permission_handler package for handle permission. Storage and Access Media Location permission has already granted by user but the issue is generated every time when pick image or video from external storage. Inside manifest file we have added android:requestLegacyExternalStorage="true"
Suddenly i get issue on the production app , please support us

Platform exception

log:

PlatformException(decode bitmap error, null, null)

E/flutter ( 2985): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(decode bitmap error, null, null)
E/flutter ( 2985): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7)
E/flutter ( 2985): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:156:18)
E/flutter ( 2985):
E/flutter ( 2985): #2 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:329:12)
E/flutter ( 2985): #3 NativeChannel.memoryToMemory (package:image_editor/src/channel.dart:37:21)
E/flutter ( 2985): #4 ImageHandler.handleAndGetUint8List (package:image_editor/src/image_handler.dart:48:30)
E/flutter ( 2985): #5 ImageEditor.editImage (package:image_editor/image_editor.dart:32:27)
E/flutter ( 2985): #6 _ImageEditWidgetState.crop (package:gintaa_people/widgets/image_edit/image_edit.dart:317:40)
E/flutter ( 2985): #7 _ImageEditWidgetState.build. (package:gintaa_people/widgets/image_edit/image_edit.dart:114:17)
E/flutter ( 2985): #8 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:779:19)
E/flutter ( 2985): #9 _InkResponseState.build. (package:flutter/src/material/ink_well.dart:862:36)
E/flutter ( 2985): #10 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
E/flutter ( 2985): #11 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:504:11)
E/flutter ( 2985): #12 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:282:5)
E/flutter ( 2985): #13 BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:217:7)
E/flutter ( 2985): #14 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:475:9)
E/flutter ( 2985): #15 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:76:12)
E/flutter ( 2985): #16 PointerRouter._dispatchEventToRoutes. (package:flutter/src/gestures/pointer_router.dart:122:9)
E/flutter ( 2985): #17 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:379:8)
E/flutter ( 2985): #18 PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:120:18)
E/flutter ( 2985): #19 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:106:7)
E/flutter ( 2985): #20 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:218:19)
E/flutter ( 2985): #21 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22)
E/flutter ( 2985): #22 GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
E/flutter ( 2985): #23 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
E/flutter ( 2985): #24 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
E/flutter ( 2985): #25 _rootRunUnary (dart:async/zone.dart:1196:13)
E/flutter ( 2985): #26 _CustomZone.runUnary (dart:async/zone.dart:1085:19)
E/flutter ( 2985): #27 _CustomZone.runUnaryGuarded (dart:async/zone.dart:987:7)
E/flutter ( 2985): #28 _invoke1 (dart:ui/hooks.dart:275:10)
E/flutter ( 2985): #29 _dispatchPointerDataPacket (dart:ui/hooks.dart:184:5)

Note - JDK 1.14, Gradle 6.4.1 and Flutter 1.17.2

How to handle orientation change?

When changing orientation from portrait to landscape and vice versa, the editor doesn't keep the changes made and image changes its scale (getting bigger or smaller).
What is the best way to handle the orientation change or should it be used only in portrait mode?

Request Update for Newest Flutter & Dart SDK

My flutter & dart version
Flutter 3.0.2 • channel stable • https://github.com/flutter/flutter.git
Framework • revision cd41fdd495 (7 days ago) • 2022-06-08 09:52:13 -0700
Engine • revision f15f824b57
Tools • Dart 2.17.3 • DevTools 2.12.2

Primary Problem

When adding flutter_image_editor package to my pubspec I've error like bellow:

Because image_editor 1.0.2 requires SDK version <2.0.0 and no versions of image_editor match >1.0.2 <2.0.0, image_editor ^1.0.2 is forbidden.
So, because peduli_bencana_presisi depends on image_editor ^1.0.2, version solving failed.

MixImageOption add rotation functionality

Hey 👋 awesome project,

would it be possible for you to add optional rotation to the MixImageOption for ImageEditor.editImage()?

I have a use-case where the user first places and rotates an image on top of another, and then I would like to mix them together with your provided blend options. As far as I can see this is not possible yet, right?

ScaleOption is not working on Android.

I'm using ScaleOption to stretch an image, and it works fine on IOS Emulator. But when testing the exact same code on Android emulator, the image doesn't stretch, keeping the original dimensions.

How to fix this?

Error: MissingPluginException(No implementation found for method memoryToMemory on channel top.kikt/flutter_image_editor)

flutter channel: dev (Flutter Web).

when run code below on Flutter Web:
final editorOption = editor.ImageEditorOption();
editorOption.addOption(editor.RotateOption(-90));
editorOption.outputFormat = editor.OutputFormat.jpeg(100);
Future list = editor.ImageEditor.editImage(image: imageData.srcImageBytes, imageEditorOption: editorOption);

i got:
Overflow on channel: top.kikt/flutter_image_editor. Messages on this channel are being discarded in FIFO fashion. The engine may not be running or you need to adjust the buffer size if of the channel.
Error: MissingPluginException(No implementation found for method memoryToMemory on channel top.kikt/flutter_image_editor)

any body help please, thank you.

Android Rotate Issue

On RotateOption degree values other Right angels shows same image multiple times on different angles

Screenshot_1639819110

pub get fails

  1. create new project
  2. write image_editor: ^1.0.0 in pubspec.yaml
  3. run flutter pub get and gets this error
Error on line 31, column 3 of pubspec.yaml: A package may not list itself as a dependency.
   ╷
31 │   image_editor: ^1.0.0
   │   ^^^^^^^^^^^^
   ╵
pub get failed (65;    ╵)
Process finished with exit code 65

flutter doctor

E:\flutter\AndroidStudio\image_editor>flutter doctor -v
[√] Flutter (Channel stable, 2.2.3, on Microsoft Windows [Version 10.0.19043.1151], locale ja-JP)
    • Flutter version 2.2.3 at C:\flutter
    • Framework revision f4abaa0735 (5 weeks ago), 2021-07-01 12:46:11 -0700
    • Engine revision 241c87ad80
    • Dart version 2.13.4

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at C:\Users\-----\AppData\Local\Android\Sdk
    • Platform android-30, build-tools 30.0.2
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[√] Android Studio (version 4.1.0)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)

[√] VS Code (version 1.58.2)
    • VS Code at C:\Users\-----\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.25.0

[√] Connected device (3 available)
    • sdk gphone x86 (mobile) • emulator-5554 • android-x86    • Android 10 (API 29) (emulator)
    • Chrome (web)            • chrome        • web-javascript • Google Chrome 92.0.4515.131
    • Edge (web)              • edge          • web-javascript • Microsoft Edge 92.0.902.62

• No issues found!

PlatformException(java.lang.IllegalArgumentException: x + width must be <= bitmap.width()

This happends only for our Android users and is triggered here in Flutter: channel.dart in NativeChannel.memoryToMemory at line 39 within image_editor

Here is the full message:

PlatformException(java.lang.IllegalArgumentException: x + width must be <= bitmap.width()
	at android.graphics.Bitmap.createBitmap(Bitmap.java:858)
	at p.a.a.c.f.d(ImageHandler.kt:3)
	at p.a.a.c.f.c(ImageHandler.kt:5)
	at p.a.a.a.k(FlutterImageEditorPlugin.kt:3)
	at p.a.a.a.c(FlutterImageEditorPlugin.kt:1)
	at p.a.a.a$b.run(FlutterImageEditorPlugin.kt:18)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
	at java.lang.Thread.run(Thread.java:920)
, , null, null)

ios工程出错

..../flutter/.pub-cache/hosted/pub.flutter-io.cn/image_editor-0.1.4/ios/Classes/FlutterImageEditorPlugin.m:2:9: 'image_editor/image_editor-Swift.h' file not found

请问这个问题怎么解决?

An exception while trying to rotate

Lib Version:1.0.0
environment:>=2.7.0 <3.0.0
Platform:Android
Platform Version:29
Target Version:29
Exception:

[ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: PlatformException(java.lang.IllegalStateException: bitmap must not be null
        at top.kikt.flutter_image_editor.FlutterImageEditorPlugin.getBitmap(FlutterImageEditorPlugin.kt:144)
        at top.kikt.flutter_image_editor.FlutterImageEditorPlugin.handle(FlutterImageEditorPlugin.kt:207)
        at top.kikt.flutter_image_editor.FlutterImageEditorPlugin.access$handle(FlutterImageEditorPlugin.kt:25)
        at top.kikt.flutter_image_editor.FlutterImageEditorPlugin$onMethodCall$$inlined$runOnBackground$1.run(FlutterImageEditorPlugin.kt:236)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:919)
    , , null, null)
    #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:597:7)
    #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:158:18)
    <asynchronous suspension>
    #2      NativeChannel.memoryToMemory (package:image_editor/src/channel.dart:39:20)
    <asynchronous suspension>
    #3      ImageEditor.editImage (package:image_editor/src/editor.dart:28:13)
    <asynchronous suspension>
    #4      PreViewPhotoPageState.loadImage (package:institute_flutter/page/preview_page.dart:209:24)
    <asynchronous suspension>

code:

    //网络加载图片,正常工作
    ui.Image _image = await loadImageByProvider(NetworkImage(url));
    final byteData = await _image.toByteData();
    assert(byteData != null);
    final bytes = byteData.buffer.asUint8List();
    final op = ImageEditorOption();
    op.addOption(RotateOption(270));
    op.outputFormat = OutputFormat.png();
    //输入是正常的
    assert(bytes != null);
    final result = await ImageEditor.editImage(image: bytes, imageEditorOption: op);

MissingPluginException (memoryToMemory) on ImageEditor.editImage

Hey there,

I've taken your example (advanced_page.dart), but when flutter executes
ImageEditor.editImage( image: img, imageEditorOption: option, ).then((result) { print(result); }).catchError((error) => print(error));
following error will be thrown:
flutter: MissingPluginException(No implementation found for method memoryToMemory on channel top.kikt/flutter_image_editor)

What am I missing?

iOS Yellow is Red.

On iOS using Colors.yellow results in red. Due to an incorrect mapping of green to use the blue value.

I've create a PR for the issue: #51

铁子这个洞什么时候补

The plugin image_editor uses a deprecated version of the Android embedding.
To avoid unexpected runtime failures, or future build failures, try to see if this plugin supports the Android
V2 embedding. Otherwise, consider removing it since a future release of Flutter will remove these deprecated APIs.

If you are plugin author, take a look at the docs for migrating the plugin to the V2 embedding:
https://flutter.dev/go/android-plugin-migration.

extend_image + image_editor 全家桶用不了了。。。

The picture turns white with coloroption

final ImageEditorOption option = ImageEditorOption();
ColorOption coloroption = ColorOption.brightness(action.payload);
option.addOption(coloroption);
Uint8List result = await ImageEditor.editFileImage(
file: File(mBean.path),
imageEditorOption: option,
);

Then load new Image:

ExtendedImage.memory(result ,
fit: BoxFit.contain,
mode: ExtendedImageMode.editor,
extendedImageEditorKey: editorKey,
initEditorConfigHandler: (mstate) {
return EditorConfig(
maxScale: 8.0,
cropRectPadding: EdgeInsets.all(20.0),
hitTestSize: 20.0,
cropAspectRatio: CropAspectRatios.ratio4_3);
})

The new picture is white

ios cropping images multiple times in a row may cause a crash

ios cropping images multiple times in a row may cause a crash

There is a memory leak in ios cropping and rotating pictures

add "CGImageRelease(resultCg)" to release memory in FIUIImageHandler.m

- (void)clip:(FIClipOption *)option {
  CGImageRef cg = outImage.CGImage;
  CGRect rect = CGRectMake(option.x, option.y, option.width, option.height);
  CGImageRef resultCg = CGImageCreateWithImageInRect(cg, rect);
  outImage = [UIImage imageWithCGImage:resultCg];
    CGImageRelease(resultCg);  // release memory
}

FIEPlugin.m

- (void)asyncExec:(VoidBlock)block {
    dispatch_async(_queue, ^(){
        @autoreleasepool {
            block();
        }
    });
}

Error UIImagePNGRepresentation

I am stuck on that error

Building com.test.test for device (ios-release)...
Automatically signing iOS for device deployment using specified development team in Xcode project: X9AA3H6FU7
Running Xcode build...

Xcode build done. 93,4s
Failed to build iOS app
Error output from Xcode build:

2020-01-10 18:32:10.216 xcodebuild[39337:1086707] DTDeviceKit: deviceType from 10a025c153535457fc6c9f1bd506a2b199804219 was NULL
** BUILD FAILED **

Xcode's output:

/Users/uogforceone/documents/flutter/.pub-cache/hosted/pub.dartlang.org/image_editor-0.1.6/ios/Classes/UIImageHandler.swift:36:20: error: 'UIImagePNGRepresentation' has been replaced by instance method 'UIImage.pngData()'
return UIImagePNGRepresentation(image)
^~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~
image.pngData
UIKit.UIImagePNGRepresentation:2:13: note: 'UIImagePNGRepresentation' was obsoleted in Swift 3
public func UIImagePNGRepresentation(_ image: UIImage) -> Data?
^
/Users/uogforceone/documents/flutter/.pub-cache/hosted/pub.dartlang.org/image_editor-0.1.6/ios/Classes/UIImageHandler.swift:38:20: error: 'UIImageJPEGRepresentation' has been replaced by instance method
'UIImage.jpegData(compressionQuality:)'
return UIImageJPEGRepresentation(image, CGFloat(format.quality) / 100)
^~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~
image.jpegData compressionQuality:
UIKit.UIImageJPEGRepresentation:2:13: note: 'UIImageJPEGRepresentation' was obsoleted in Swift 3
public func UIImageJPEGRepresentation(_ image: UIImage, _ compressionQuality: CGFloat) -> Data?
^
warning: /Users/uogforceone/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/MS5960MZXDD7/UIKit-2LM3EQU7VVY4O.pcm: No such file or directory
note: while processing /Users/uogforceone/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/MS5960MZXDD7/UIKit-2LM3EQU7VVY4O.pcm
warning: /Users/uogforceone/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/MS5960MZXDD7/Foundation-A3SOD99KJ0S9.pcm: No such file or directory
note: while processing /Users/uogforceone/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/MS5960MZXDD7/Foundation-A3SOD99KJ0S9.pcm
warning: /Users/uogforceone/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/MS5960MZXDD7/MobileCoreServices-FJAFSB4GMRIG.pcm: No such file or directory
note: while processing /Users/uogforceone/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/MS5960MZXDD7/MobileCoreServices-FJAFSB4GMRIG.pcm
warning: /Users/uogforceone/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/MS5960MZXDD7/ObjectiveC-1KD62J152BYGO.pcm: No such file or directory
note: while processing /Users/uogforceone/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/MS5960MZXDD7/ObjectiveC-1KD62J152BYGO.pcm
warning: /Users/uogforceone/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/MS5960MZXDD7/ImageIO-1I03OOXLFD3W9.pcm: No such file or directory
note: while processing /Users/uogforceone/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/MS5960MZXDD7/ImageIO-1I03OOXLFD3W9.pcm
warning: /Users/uogforceone/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/MS5960MZXDD7/CoreFoundation-10I2D2XL7L7X9.pcm: No such file or directory
note: while processing /Users/uogforceone/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/MS5960MZXDD7/CoreFoundation-10I2D2XL7L7X9.pcm
warning: /Users/uogforceone/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/MS5960MZXDD7/Darwin-MI6WZSG1PNOM.pcm: No such file or directory
note: while processing /Users/uogforceone/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/MS5960MZXDD7/Darwin-MI6WZSG1PNOM.pcm
warning: /Users/uogforceone/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/MS5960MZXDD7/CoreGraphics-1TH4RJJRQVFOC.pcm: No such file or directory
note: while processing /Users/uogforceone/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/MS5960MZXDD7/CoreGraphics-1TH4RJJRQVFOC.pcm
warning: /Users/uogforceone/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/MS5960MZXDD7/Photos-3GN2TRT9ZVVF.pcm: No such file or directory
note: while processing /Users/uogforceone/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/MS5960MZXDD7/Photos-3GN2TRT9ZVVF.pcm
note: Using new build system
note: Planning build
note: Constructing build description

Decode image feature

The popular image library has a method to decode an image by bytes and retrieve the image info such as width and height. May I know if this is a planned feature?

Text is auto wrapping if the text width and left offset is greater than the width of the image

Request:

If the input text's width or the left offset is greater than the width of the image, the text is auto-wrapping.

Is there any way to disable auto-wrapping of text Strings? For example if I scaled the font size of the text and it becomes larger than the background image, or if I moved it closer to the edge of the image, the text outputs in multiple lines.

// if x-offset is greater than image

textOption.addText(
  EditorText(
    offset: Offset(x, y),
    text: this._controller.text,
    fontSizePx: size,
    color: Colors.white,
  ),
);

Kindly refer to the images below if my request is unclear. Thanks for the great package.

Input

image

Current Output:

image

ios图片裁剪后得到的图片翻转了90度

我在使用iOS裁剪图片时发现图片裁剪后翻转了90度,

Future<List<int>> cropImageDataWithNativeLibrary(
    {ExtendedImageEditorState state}) async {
  print("native library start cropping");

  final cropRect = state.getCropRect();
  final action = state.editAction;

  final rotateAngle = action.rotateAngle.toInt();
  final flipHorizontal = action.flipY;
  final flipVertical = action.flipX;
  final img = state.rawImageData;

  ImageEditorOption option = ImageEditorOption();

  if (action.needCrop) option.addOption(ClipOption.fromRect(cropRect));

  if (action.needFlip)
    option.addOption(
        FlipOption(horizontal: flipHorizontal, vertical: flipVertical));

  if (action.hasRotateAngle) option.addOption(RotateOption(rotateAngle));

  final start = DateTime.now();
  final result = await ImageEditor.editImage(
    image: img,
    imageEditorOption: option,
  );

  print("${DateTime.now().difference(start)} :total time");
  return result;
}

通过debug可以发现option.groupList中只有一个ClipCption

is there a way to rotate by angle?

I would like to add a slider to rotate:

this is how far I got:

Expanded(
  child: Slider(
    divisions: 361,
    value: _rotation,
    min: -180,
    max: 180,
    label: '$_rotation°',
    onChanged: (n) {
      setState(() {
        _rotation = n.roundToDouble();
        editorKey.currentState.editAction.rotate(
            _rotation,
            editorKey.currentState.getCropRect(),
            BoxFit.fitHeight);
      });
    },
  ),
),

It rotates into oblivion 😅

add text to image

Why my text add only to left top corner? i try change offset: Offset(1, 1),but it do not working .

textOption.addText(
      EditorText(
        text: '$lat $lng',
        fontSizePx: size,
        textColor: const Color(0xFF995555),
        offset: Offset(1, 1),
      ),
    );
    option.outputFormat = const OutputFormat.jpeg(100);

    option.addOption(textOption);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.