對於懶惰的,這裏有一個可重複使用的功能:
public static void copyExif(String oldPath, String newPath) throws IOException
{
ExifInterface oldExif = new ExifInterface(oldPath);
String[] attributes = new String[]
{
ExifInterface.TAG_APERTURE,
ExifInterface.TAG_DATETIME,
ExifInterface.TAG_DATETIME_DIGITIZED,
ExifInterface.TAG_EXPOSURE_TIME,
ExifInterface.TAG_FLASH,
ExifInterface.TAG_FOCAL_LENGTH,
ExifInterface.TAG_GPS_ALTITUDE,
ExifInterface.TAG_GPS_ALTITUDE_REF,
ExifInterface.TAG_GPS_DATESTAMP,
ExifInterface.TAG_GPS_LATITUDE,
ExifInterface.TAG_GPS_LATITUDE_REF,
ExifInterface.TAG_GPS_LONGITUDE,
ExifInterface.TAG_GPS_LONGITUDE_REF,
ExifInterface.TAG_GPS_PROCESSING_METHOD,
ExifInterface.TAG_GPS_TIMESTAMP,
ExifInterface.TAG_IMAGE_LENGTH,
ExifInterface.TAG_IMAGE_WIDTH,
ExifInterface.TAG_ISO,
ExifInterface.TAG_MAKE,
ExifInterface.TAG_MODEL,
ExifInterface.TAG_ORIENTATION,
ExifInterface.TAG_SUBSEC_TIME,
ExifInterface.TAG_SUBSEC_TIME_DIG,
ExifInterface.TAG_SUBSEC_TIME_ORIG,
ExifInterface.TAG_WHITE_BALANCE
};
ExifInterface newExif = new ExifInterface(newPath);
for (int i = 0; i < attributes.length; i++)
{
String value = oldExif.getAttribute(attributes[i]);
if (value != null)
newExif.setAttribute(attributes[i], value);
}
newExif.saveAttributes();
}
謝謝西奧,我很欣賞這個答案並已接受它。你有鏈接瞭解更多關於這個的信息「根據Android操作系統版本的不同,ExifInterface有時會破壞EXIF數據。」 –
這是基於我的經驗,我不是第一個發現ExifInterface是越野車的人[1]。根據我在未來幾天的時間,我可能會彙總一些說明性的案例並回報。 [1] http://mail-archives.apache.org/mod_mbox/commons-issues/201106.mbox/%[email protected]e.org%3E – Theo
@Theo i'我測試了你的代碼,它似乎複製了一些設備和圖像的大部分/全部屬性。不能很好複製的屬性示例:ISOSpeedRatings,FocalLength,FNumber。你能解釋一下它怎麼可能?我已經用Android 4.4.2在nexus 4設備上測試過它,並比較了在原始文件和新文件上創建的ExifInterface。 –