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
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
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