btastic / flutter_native_image

Native Flutter Image tools
Other
340 stars 137 forks source link

How to use this plugin with image from Assets #87

Closed netgfx closed 3 years ago

netgfx commented 3 years ago

I'm trying to load an image from Assets but it can't find it and I can't use rootBundle to fetch it because the plugin doesn't accept byte data. Is there an example on how to load via the assets library or where to put the assets in order to load via getApplicationDocumentsDirectory?

btastic commented 3 years ago

Thats the main issue this plugin is trying to tackle. Avoid loading byte data with flutter directly.

I don't know what changed in the recent months / years in flutter, since I don't work with it anymore (time related).

You could try fiddling around with the native calls and transfer over a byte array, then process it from there. Unfortunately I don't have the time to work on this.

If you have any questions, I will try my best to help, but I think this is a bit harder to do.

netgfx commented 3 years ago

I ended up making copies of the images inside document directory (it is not optimal but for now it works)

final ByteData data = await rootBundle.load('assets/monster1.png');
String dir = (await getApplicationDocumentsDirectory()).path;
File path = await writeToFile(data, '$dir/monster1.png');

File croppedFile = await uiImage.FlutterNativeImage.cropImage(path.path, 0, 0, 192, 212);
Uint8List bytes = croppedFile.readAsBytesSync();