flutter_native_image
flutter_native_image copied to clipboard
Preserve exif information after crompessed file
I have a file taken from ImagePicker.pickImage that I want to resize and then I want to know his orientation because I want to it be always in portrait orientation for write image in pdf.
On Android I noticed after compressed file with flutter_native_image the exif information is lost. if you use brendan-duncan/image for decode image you'll notice that orientation is null.
File compressedFile = await FlutterNativeImage.compressImage(dat[i].path, quality: 80,
targetWidth: 600,
targetHeight: (properties.height * 600 / properties.width).round());
List<int> byte = compressedFile.readAsBytesSync();
Im.Image img = Im.decodeImage(byte);
int orientation = img.exif.orientation; # is null
Hmm according to this part of my code, it should keep the exif information: https://github.com/btastic/flutter_native_image/blob/master/android/src/main/java/com/example/flutternativeimage/FlutterNativeImagePlugin.java#L83 Especially this part: https://github.com/btastic/flutter_native_image/blob/master/android/src/main/java/com/example/flutternativeimage/FlutterNativeImagePlugin.java#L197
If you can, I'd like to have a look at your picture to see what is happening in your case.
This is screenshot

Ok it looks like you are using brendan duncans library instead of mine. I am not sure about his implementation of his library, but I guess his library does not keep exif information. Maybe you could post a simplified version of your code so I could have a look at it.
dependencies:
image_picker: ^0.4.10
cupertino_icons: ^0.1.2
flutter_native_image:
git: https://github.com/btastic/flutter_native_image.git
image: ^2.0.4
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: null,
body: Text(''),
floatingActionButton: FloatingActionButton(
onPressed: () async {
File fileFromPicker = await ImagePicker.pickImage(source: ImageSource.camera);
ImageProperties properties = await FlutterNativeImage.getImageProperties(fileFromPicker.path);
File compressedFile = await FlutterNativeImage.compressImage(fileFromPicker.path, quality: 100,
targetWidth: 600,
targetHeight: (properties.height * 600 / properties.width).round());
List<int> byte = compressedFile.readAsBytesSync();
Im.Image img = Im.decodeImage(byte);
int orientation = img.exif.orientation;
print('orientation ' + orientation.toString());
// ...
},
tooltip: 'picker',
child: Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
So I fiddled around with this for a bit and I found that there seems to be an issue. For the image resizing I am actually using googles code and I just checked on their repo, and they have the same issues right now aswell.
https://github.com/flutter/flutter/issues/12921
It is now fixed!
They added an helper class that could be used in this plugin I guess.
- (iOS) FLTImagePickerMetaDataUtil.m
- (Android) ExifDataCopier.java
@btastic did you plan any update about this issue?
Currently I am busy with other personal stuff and I don't have much time to have a deeper look at this. This is also something I can not easily implement without having an iOS device. Sorry for the inconveniences.