很多時候我們都要對我們的圖片信息進行一些處理,比如向圖片中寫入經緯度,拍攝時間,設備信息,作者等等。
這個時候我們就要對我們的圖片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