Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing EXIF metadata to images in Android

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

like image 755
vpk Avatar asked Jul 14 '10 12:07

vpk


People also ask

How do you write an EXIF?

To write Exif data to a JPEG, you need to write an APP1/Exif segment as part of the normal JIF structure. The EXIFWriter will write the data you should put inside this segment only. Everything else must be provided by you. There are multiple ways of achieving this.

Does Android save EXIF data?

Checking the Exif data of a photo on an Android phone or tablet is pretty easy. You don't need access to any special apps. The gallery app of your phone or Google Photos can show the most important bits from the Exif data of your photos.

Can you change metadata on a photo Android?

While you can't change all metadata, Google Photos allows you to create and change some image metadata. Tap a photo where you want to change metadata. The image should be in full view. Swipe up on the image and the metadata display will be shown.


2 Answers

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

like image 171
vpk Avatar answered Oct 12 '22 14:10

vpk


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

like image 26
M.Hefny Avatar answered Oct 12 '22 14:10

M.Hefny