From c6706623e070b8ae12ae2c190f58d76b35ec81ce Mon Sep 17 00:00:00 2001 From: Lauri Matti Saarni Date: Tue, 6 Mar 2018 14:05:29 +0700 Subject: [PATCH] Add the missing exif data for Android Some of the exif data has been previously been lost. Now they are included as the sub directory is looped and names of exif data are formated to match with ExifInterface class requirements. --- .../com/lwansbrough/RCTCamera/MutableImage.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/com/lwansbrough/RCTCamera/MutableImage.java b/android/src/main/java/com/lwansbrough/RCTCamera/MutableImage.java index a2f3a5a..cad761b 100644 --- a/android/src/main/java/com/lwansbrough/RCTCamera/MutableImage.java +++ b/android/src/main/java/com/lwansbrough/RCTCamera/MutableImage.java @@ -15,6 +15,7 @@ import com.drew.metadata.Metadata; import com.drew.metadata.MetadataException; import com.drew.metadata.Tag; import com.drew.metadata.exif.ExifIFD0Directory; +import com.drew.metadata.exif.ExifSubIFDDirectory; import com.facebook.react.bridge.ReadableMap; import java.io.BufferedInputStream; @@ -179,7 +180,6 @@ public class MutableImage { ExifInterface exif = new ExifInterface(file.getAbsolutePath()); // copy original exif data to the output exif... - // unfortunately, this Android ExifInterface class doesn't understand all the tags so we lose some for (Directory directory : originalImageMetaData().getDirectories()) { for (Tag tag : directory.getTags()) { int tagType = tag.getTagType(); @@ -188,6 +188,18 @@ public class MutableImage { } } + // Add missing exif data from a sub directory + ExifSubIFDDirectory directory = originalImageMetaData() + .getFirstDirectoryOfType(ExifSubIFDDirectory.class); + for (Tag tag : directory.getTags()) { + int tagType = tag.getTagType(); + // As some of exif data does not follow naming of the ExifInterface the names need + // to be transformed into Upper camel case format. + String tagName = tag.getTagName().replaceAll(" ", ""); + Object object = directory.getObject(tagType); + exif.setAttribute(tagName, object.toString()); + } + writeLocationExifData(options, exif); if(hasBeenReoriented)