Exif讀取類
Android提供了讀取寫入Exif的API,但很可惜,這個API只能由指定文件名讀取、寫入Exif,效率低得可憐。
不得已,把Android系統代碼裏圖庫的一段摘了過來。
有Android源碼的看源碼中 packages/apps/Gallery2/ 部分,
沒有或者圖方便的直接看這裏:
https://github.com/jxt1234/ThirdPartyUsefulCode/tree/master/android_app/exif
使用方法
和SDK中那個API用法基本一致,可參考:
http://www.cnblogs.com/hyzhou/p/3336812.html
不過這個Exif庫支持從內存、流之中直接讀取寫入,方便很多。
用到的接口只有
ExifInterface
其中讀取和寫入的接口支持內存/流。
readExif 讀取
writeExif 寫入
其他用法一樣。
使用實例
讀取Exif中的縮略圖示例
public void onHandle(final byte[] data){
ExifInterface exif = new ExifInterface();
try {
exif.readExif(data);
} catch (IOException e1) {
e1.printStackTrace();
}
Bitmap thumbnail_origin = null;
if (exif.hasThumbnail()){
thumbnail_origin = exif.getThumbnailBitmap();
}
/*.......*/
}
寫入:
//Bitmap result = XXXXXXX;
//String file = YYYY;
//ExifInterface exif = ZZZZ;
FileOutputStream fstream = new FileOutputStream(file);
try {
exif.writeExif(result, fstream);
} catch (IOException e1) {
}