Merge pull request #1338 from laurisaarni/exif-exposuretime-format

Reformat exposure time in exif data.
This commit is contained in:
João Guilherme Fidelis 2018-03-14 15:27:16 -03:00 committed by GitHub
commit 637e7b7a92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -197,8 +197,12 @@ public class MutableImage {
// to be transformed into Upper camel case format.
String tagName = tag.getTagName().replaceAll(" ", "");
Object object = directory.getObject(tagType);
if (tagName.equals(ExifInterface.TAG_EXPOSURE_TIME)) {
exif.setAttribute(tagName, convertExposureTimeToDoubleFormat(object.toString()));
} else {
exif.setAttribute(tagName, object.toString());
}
}
writeLocationExifData(options, exif);
@ -211,6 +215,18 @@ public class MutableImage {
}
}
// Reformats exposure time value to match ExifInterface format. Example 1/11 -> 0.0909
// Even the value is formatted as double it is returned as a String because exif.setAttribute requires it.
private String convertExposureTimeToDoubleFormat(String exposureTime) {
if(!exposureTime.contains("/"))
return;
String exposureFractions[]= exposureTime.split("/");
double divider = Double.parseDouble(exposureFractions[1]);
double exposureTimeAsDouble = 1.0f / divider;
return Double.toString(exposureTimeAsDouble);
}
private void rewriteOrientation(ExifInterface exif) {
exif.setAttribute(ExifInterface.TAG_ORIENTATION, String.valueOf(ExifInterface.ORIENTATION_NORMAL));
}