Writing EXIF metadata to images in Android

一笑奈何 提交于 2019-12-04 23:36:35

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

M.Hefny
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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!