Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing and saving EXIF tags (attributes) to JPEG image in Android

I've managed to use ExifInterface to read EXIF tags/attributes (meta data) from a JPEG on my phone, and I can apparently also set attributes and save attributes. The strange thing is, if I do set+save on an image file, my app is able to get the attribute and display it. I can also verify in another app (Photo Editor on Google Play) that the EXIF-data is indeed written.

ExifInterface exif = new ExifInterface(path_to_image); 
String x = exif.getAttribute("UserComment"); // here, x is always null...

exif.setAttribute("UserComment", "testtest");
exif.saveAttributes();

x = exif.getAttribute("UserComment");  // x = "testtest"

Now, the EXIF is saved to the JPEG file: see screenshot of my app. This is also verified by Photo Editor app: see screenshot of that.

But, if I comment out set+save and just do get (on the same image as above), my app fails to get/see the attribute:

ExifInterface exif = new ExifInterface(path_to_image); 
String x = exif.getAttribute("UserComment");  // x = null (although we know it isn't)

So: since the Photo Editor app can read the data, I'm doing something wrong (with the writing/saving). Also, if I re-run the set+save on the same image file, my app duplicates the same tag! Is there something more to this than simply set+save, then get?

Update: It seems the problem is device-dependent. Although the UserComment does not appear to be among the tags explicitly supported by ExifInterface, certain devices are nevertheless able to set and get the value in the tag. It works on Nexus'es, but not on my Sony Xperia. Please take a look at my code for getting (query) and setting (update) the UserComment tag in my other post on Content Providers.

like image 968
joakimk Avatar asked Nov 01 '22 06:11

joakimk


1 Answers

Solution is to not use ExifInterface, it seems. I'm going to try https://github.com/sephiroth74/Android-Exif-Extended

Update: Even better, use Apache Sanselan, https://commons.apache.org/proper/commons-imaging/javadocs/api-release/org/apache/sanselan/Sanselan.html

like image 81
joakimk Avatar answered Nov 12 '22 20:11

joakimk