18

I want to store some metadata in images. My camera application gives me a bitmap, which I store in the storage (MediaStore) device. In addition to this, I want to add a few tags to the picture in its metadata. I think EXIF is a good way of doing this. But I couldn't find good references on how to do this.

If there are some tools to achieve this task in Android programming, please let me know.

Thanks

2

2 Answers 2

11

Ok, Somebody (offline) pointed me to a useful resource. The ExifInterface looks like what I was searching for. Android-er has a post demonstrating how to read EXIF metadata in Android and I think writing should not be very different.

I don't know, but can we EXIF to write arbitrary metadata, ie. other than those specified in the ExifInterface documentation (like latitude, longitude, flash etc). If not, what could be a preferred method of writing arbitrary metadata to image files?

Thanks

Sign up to request clarification or add additional context in comments.

3 Comments

Could you make a new question from your 2nd paragraph so we can answer it properly? (IMHO the answer is Yes)
I've also found this library useful: github.com/dragon66/pixymeta-android
10
public static void writeFile (File photo, double latitude, double longitude) throws IOException{ ExifInterface exif = null; try{ Log.v("latiDouble", ""+latitude); Log.v("longiDouble", ""+longitude); exif = new ExifInterface(photo.getCanonicalPath()); if (exif != null) { double latitu = latitude; double longitu = longitude; double alat = Math.abs(latitu); double along = Math.abs(longitu); String stringLati = convertDoubleIntoDegree(alat); String stringLongi = convertDoubleIntoDegree(along); exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, stringLati); exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, stringLongi); Log.v("latiString", ""+ stringLati); Log.v("longiString", ""+ stringLongi); exif.saveAttributes(); String lati = exif.getAttribute (ExifInterface.TAG_GPS_LATITUDE); String longi = exif.getAttribute (ExifInterface.TAG_GPS_LONGITUDE); Log.v("latiResult", ""+ lati); Log.v("longiResult", ""+ longi); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } 

I copied the answer from here

4 Comments

why do u abs latitude longitude?)
Thank you for your question, I double checked the code. yes it is correct to use ABS, as the plus & minus appears in exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF, lat>0?"N":"S"); and in exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF, lon>0?"E":"W");
I mean code you posted here only uses positive values and ignores negative. I know that both are used in formulas usually but not in your code you posted here
In my code the positive and negative values are translated to N & S and E & W. SO they are not ignored.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.