I am using exif plugin to identify orientation of image. But it is showing me an error following error:
I/flutter ( 7355): Exception in image -- NoSuchMethodError: The getter 'printable' was called on null.
Here is my code:
//Method to set orientation of images Future fixExifRotation(String imagePath) async { final originalFile = File(imagePath);
List<int> imageBytes = await originalFile.readAsBytes(); final originalImage = img.decodeImage(imageBytes); final height = originalImage.height; final width = originalImage.width; // We'll use the exif package to read exif data // This is map of several exif properties // Let's check 'Image Orientation' final exifData = await readExifFromBytes(imageBytes); for (String key in exifData.keys) { print("$key (${exifData[key].tagType}): ${exifData[key]}"); } img.Image fixedImage; if (exifData['Image Orientation'].printable.contains('Rotated 180')) { fixedImage = img.copyRotate(originalImage, 180); }else if (exifData['Image Orientation'].printable.contains('Horizontal (normal)')) { return originalFile; } else{ return originalFile; } final fixedFile = await originalFile.writeAsBytes(img.encodeJpg(fixedImage)); return fixedFile; }
Issue is in
final exifData = await readExifFromBytes(imageBytes);