Reading EXIF Data in Flutter fast

Viewed 19

I try to analyze many pictures and want to get the exact date and time when they were taken. This was the first option I used:

File file = File(path);
DateTime dt = file.lastModified();
//or
dt = file.lastAccessed();

But I found out, that those two possibilities don't always get the real DateTime, when the picture was taken, but that there are DateTimes in the EXIF-Metadata of the image. So I took this https://pub.dev/packages/exif EXIF library, which resulted in something like the following code:

File file = File(path);
final fileBytes = file.readAsBytesSync();
final data = await readExifFromBytes(fileBytes, details: false);
if (data.containsKey('EXIF DateTimeOriginal')) {
      DateTime dt = DateTime.parse(data['EXIF DateTimeOriginal'].toString().replaceAll(':', ''));
    } else {
      DateTime dt = await file.lastModified();
    }

Now, to conclude: This is slow. Not only to read ´the whole file as bytes takes some time, but the readEXIFFromBytes too. The argument "details: false" in the code seems to have a positive input for the speed, because of which I included it.

Is there a way to read the real DateTime, when the picture was taken, faster than this?

0 Answers
Related