안드로이드에서 Bitmap.createScaledBitmap 을 사용해서 이미지 크기를 변경하면 exif 정보가 날라간다.
그래서 이것을 유지시켜주는 유틸을 만들었다.
먼저 크기는 변경되기 때문에 크기의 exif 정보만 빼고 나머지를 그대로 복사하는 copyExifWithoutLengthWitdth 함수를 정의한다.
private static void copyExifWithoutLengthWidth(ExifInterface src,ExifInterface dest) {
for (Field f:ExifInterface.class.getFields()) {
String name = f.getName();
if (!name.startsWith("TAG_")) {
continue;
}
String key = null;
try {
key = (String)f.get(null);
} catch (Exception e) {
continue;
}
if (key == null) {
continue;
}
if (key.equals(ExifInterface.TAG_IMAGE_LENGTH) || key.equals(ExifInterface.TAG_IMAGE_WIDTH)) {
continue;
}
String value = src.getAttribute(key);
if (value == null) {
continue;
}
dest.setAttribute(key, value);
}
}
ExifInterface originalExif = new ExifInterface(originalFile.getAbsolutePath());
ExifInterface finalExif = new ExifInterface(finalFile.getAbsolutePath());
copyExifWithoutLengthWidth(originalExif,finalExif);
finalExif.saveAttributes();