0

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);
Code Hunter
  • 10,075
  • 23
  • 72
  • 102
  • 1
    `exifData['Image Orientation']` is null - the error you get says it pretty clear: `NoSuchMethodError: The getter 'printable' was called on null.` – pskink Sep 29 '20 at 07:19
  • Does this answer your question? [What is a NoSuchMethod error and how do I fix it?](https://stackoverflow.com/questions/64049102/what-is-a-nosuchmethod-error-and-how-do-i-fix-it) – nvoigt Sep 29 '20 at 07:31

1 Answers1

0

You did not mention where the image is coming from

in my case I am using image_picker and the problem was using an emulator for taking a picture. Using a real device did the trick

Dharman
  • 30,962
  • 25
  • 85
  • 135
Ali Izadyar
  • 140
  • 1
  • 2
  • 13