when the camera after taking a picture, the position of the picture becomes wrong and not straight, here's the code I made
Future pickImage(ImageSource source) async {
try {
final image = await ImagePicker.pickImage(source: source);
if(image == null) return;
final imageTemporary = File(image.path);
date = DateTime.now().toString();
print(imageTemporary);
setState(() {
this.image = imageTemporary;
this.date = date;
});
} on PlatformException catch(e) {
print('failed to pick image');
}
}
CodePudding user response:
I think it’s a bug in the library have you tried on physical device ? If still the issue persists then you can use this workaround :
Future<File> rotateAndCompressAndSaveImage(File image) async {
int rotate = 0;
List<int> imageBytes = await image.readAsBytes();
Map<String, IfdTag> exifData = await readExifFromBytes(imageBytes);
if (exifData != null &&
exifData.isNotEmpty &&
exifData.containsKey("Image Orientation")) {
IfdTag orientation = exifData["Image Orientation"];
int orientationValue = orientation.values[0];
if (orientationValue == 3) {
rotate = 180;
}
if (orientationValue == 6) {
rotate = -90;
}
if (orientationValue == 8) {
rotate = 90;
}
}
List<int> result = await FlutterImageCompress.compressWithList(imageBytes,
quality: 100, rotate: rotate);
await image.writeAsBytes(result);
return image;
}