fluttercandies / flutter_image_editor

Flutter plugin, support android/ios.Support crop, flip, rotate, color martix, mix image, add text. merge multi images.
Apache License 2.0
414 stars 126 forks source link

ScaleOption isn't working as expected #47

Closed ngoan98tv closed 4 years ago

ngoan98tv commented 4 years ago

I'm trying to scale a 2000x2000 image to 300x300 by addOption(ScaleOption(300,300)) but it's not working.

CaiJingLong commented 4 years ago

More info? iOS or android?

ngoan98tv commented 4 years ago

More info? iOS or android?

Android, I don't see any thing strange in debug logs. It just run normally, but when I check the output image, it stays original size.

CaiJingLong commented 4 years ago

Can you provide some gist code? I used the example and found no problems.

CaiJingLong commented 4 years ago

a

ngoan98tv commented 4 years ago

The example code also works well with me, but it's not work on my app. This's a snip of my code.

Future<List<int>> cropImageDataWithNativeLibrary() async {
    print('Start cropping');
    final state = editorKey.currentState;
    final cropRect = state.getCropRect();
    final action = state.editAction;

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

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

    option.addOption(ScaleOption(300, 300));
    option.outputFormat = OutputFormat.png(80);

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

    print('${DateTime.now().difference(start)} : total time');
    print('${result.lengthInBytes} bytes');

    return result;
  }
ngoan98tv commented 4 years ago

I don't know why, but now it's work. Thanks for quickly support, @CaiJingLong