fluttercandies / extended_image

A powerful official extension library of image, which support placeholder(loading)/ failed state, cache network, zoom pan image, photo view, slide out page, editor(crop,rotate,flip), paint custom etc.
https://fluttercandies.github.io/extended_image/
MIT License
1.93k stars 503 forks source link

How to get the data from an ExtendedImge after editing #675

Closed jwbrown closed 6 months ago

jwbrown commented 6 months ago

Platforms

dart, Android

Description

The editing works perfectly, i am testing with a Flip at the moment. However, when extracting the data to save the image to a file, I am getting the original file data and not the edited data.

My code

final GlobalKey editorKey = GlobalKey();

ExtendedImage img = ExtendedImage.file( File(widget.filePath), fit: BoxFit.contain, mode: ExtendedImageMode.editor, extendedImageEditorKey: editorKey, cacheRawData: true, initEditorConfigHandler: (state) => EditorConfig( maxScale: 8.0, cropRectPadding: EdgeInsets.all(20.0), hitTestSize: 20.0, ), );

// in an icon button editorKey.currentState?.flip();

// the image is flipped perfectly on screen // for saving the current code i am trying is final state = editorKey.currentState; if (state == null) { return; } Uint8List? editedImage = state.rawImageData; File imgFile = File(widget.filePath); imgFile.writeAsBytesSync(editedImage!); // with testing for null editedImage code left out

Try do it

I can see that the image data that is provided in the original file load, is identical to that returned from the

Uint8List? editedImage = state.rawImageData;

I have also attempted going to the ImageProvider logic with an ImageStreamListener but could not get that to work either.

Any help/direction will be appreciated

zmtzawqlp commented 6 months ago

https://github.com/fluttercandies/extended_image/blob/618a0f06f145db3cf2b6db8712cee5e472936843/example/lib/common/utils/crop_editor_helper.dart#L53

you can use this method ,but it's slow.

jwbrown commented 6 months ago

Thanks for the suggestion. Strangely it is giving me the same data as the originally loaded image, not the data from after a flip() or rotate() call...

i.e. get the same return after various edits (that show perfectly on the screen) as i got when i first loaded the image... It feels like this is the cached data i am getting back, and not the current image.

This is the function i am using:

Future<Uint8List?> getImageFromNew() async { final state = editorKey.currentState; if (state == null || state.image == null) { return null; } Uint8List result = (await state.image!.toByteData(format: ui.ImageByteFormat.png))!.buffer.asUint8List(); return result; }

is there something i am doing wrong?

zmtzawqlp commented 6 months ago

https://github.com/fluttercandies/extended_image/blob/618a0f06f145db3cf2b6db8712cee5e472936843/example/lib/common/utils/crop_editor_helper.dart#L200

you can the data after fip at this place

jwbrown commented 6 months ago

Thank you very, very much.... this has solved the problem for me :)