codenameakshay / image-editor

This is a beautiful open-source image-editing app for Android/iOS. It is built with Dart on top of Google's Flutter Framework.
BSD 3-Clause "New" or "Revised" License
55 stars 10 forks source link

you should set [ExtendedImageProvider.cacheRawData] to true #8

Closed gbbest15 closed 3 years ago

gbbest15 commented 3 years ago

how can i set this to true, i have no idea how to set this.. here is the function

 Future<void> crop([bool test = false]) async {
    final ExtendedImageEditorState state = editorKey.currentState;
    ExtendedFileImageProvider(image, cacheRawData: true);
    final Rect rect = state.getCropRect();
    final EditActionDetails action = state.editAction;
    final double radian = action.rotateAngle;

    final bool flipHorizontal = action.flipY;
    final bool flipVertical = action.flipX;
    final Uint8List img = state.rawImageData;

    final option = ImageEditorOption();

    option.addOption(ClipOption.fromRect(rect));
    option.addOption(
        FlipOption(horizontal: flipHorizontal, vertical: flipVertical));
    if (action.hasRotateAngle) {
      option.addOption(RotateOption(radian.toInt()));
    }

    option.addOption(ColorOption.saturation(sat));
    option.addOption(ColorOption.brightness(bright + 1));
    option.addOption(ColorOption.contrast(con));

    option.outputFormat = const OutputFormat.jpeg(100);

    print(const JsonEncoder.withIndent('  ').convert(option.toJson()));

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

    print('result.length = ${result?.length}');

    final Duration diff = DateTime.now().difference(start);
    image?.writeAsBytesSync(result);
    print('image_editor time : $diff');
    //--here is the uploading url--
    final imageUrl = await uploadingFile(uploadFile: image);
    // storing the url to console
    firestore
        .collection('Image')
        .doc(auth.currentUser?.uid)
        .collection('Photos')
        .doc()
        .set({
      'picture': imageUrl,
    });
  }
codenameakshay commented 3 years ago

You can implement this by passing true to cacheRawData property -

ExtendedImage(
          color: bright > 0
              ? Colors.white.withOpacity(bright)
              : Colors.black.withOpacity(-bright),
          colorBlendMode: bright > 0 ? BlendMode.lighten : BlendMode.darken,
          image: ExtendedFileImageProvider(image!, cacheRawData: true), // set this to true
          height: MediaQuery.of(context).size.width,
          width: MediaQuery.of(context).size.width,
          extendedImageEditorKey: editorKey,
          mode: ExtendedImageMode.editor,
          fit: BoxFit.contain,
          initEditorConfigHandler: (ExtendedImageState? state) {
            return EditorConfig(
              maxScale: 8.0,
              cropAspectRatio: cropRatio,
            );
          },
        ),