1. 程式人生 > >Android 實現對圖片 Exif 的修改(Android 自帶的方法)

Android 實現對圖片 Exif 的修改(Android 自帶的方法)

很多時候我們都要對我們的圖片資訊進行一些處理,比如向圖片中寫入經緯度,拍攝時間,裝置資訊,作者等等。

這個時候我們就要對我們的圖片Exif進行寫入資訊的操作,當然,我們想知道圖片的Exif資訊,也可以對Exif資訊的讀取操作。

因為Android本身有對圖片Exif操作的方法,所以就不需要額外匯入其他 jar

下面先貼出程式碼:

<span style="font-size:14px;">import android.media.ExifInterface;
import android.util.Log;

import java.io.IOException;

/**
 * Created by long on 2016/3/22.
 */
public class ModifyExif {
    private static ExifInterface exif = null;

    //設定exif
    public static void setExif
            (String filepath,String longitude,String latitude,String time){
        try{
            exif = new ExifInterface(filepath);     //根據圖片的路徑獲取圖片的Exif
        }catch (IOException ex){
            Log.e("Mine","cannot read exif",ex);
        }
        exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE,longitude);    //把經度寫進exif
        exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, latitude);     //把緯度寫進exif
        exif.setAttribute(ExifInterface.TAG_DATETIME,time);              //把時間寫進exif
        exif.setAttribute(ExifInterface.TAG_MAKE,longitude);             //把經度寫進MAKE 裝置的製造商,當然這樣也是可以的,大家都是Stirng型別
        exif.setAttribute(ExifInterface.TAG_MODEL,latitude);             //把緯度寫進MODEL
        try{
            exif.saveAttributes();         //最後儲存起來
        }catch (IOException e){
            Log.e("Mine","cannot save exif",e);
        }
    }

    //獲取exif
    public static ExifInterface getExif(String filepath){
        try {
            exif = new ExifInterface(filepath);    //想要獲取相應的值:exif.getAttribute("對應的key");比如獲取時間:exif.getAttribute(ExifInterface.TAG_DATETIME);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return exif;
    } <span style="font-family: Arial, Helvetica, sans-serif;">}</span></span>

相應文章分享:

http://blog.csdn.net/xywy2008/article/details/38089789

http://blog.csdn.net/gao_chun/article/details/46854323

http://blog.csdn.net/fengyud/article/details/6147597

http://blog.csdn.net/kook_okko/article/details/2635294

http://blog.csdn.net/dc15822445347/article/details/8142103

關注公眾號,分享乾貨,討論技術