fixed exposure time format
This commit is contained in:
parent
f0818066b5
commit
67a5e19e23
1 changed files with 17 additions and 7 deletions
|
@ -20,6 +20,7 @@ import com.adobe.internal.xmp.properties.XMPProperty;
|
||||||
import com.adobe.internal.xmp.properties.XMPPropertyInfo;
|
import com.adobe.internal.xmp.properties.XMPPropertyInfo;
|
||||||
import com.drew.imaging.ImageMetadataReader;
|
import com.drew.imaging.ImageMetadataReader;
|
||||||
import com.drew.lang.GeoLocation;
|
import com.drew.lang.GeoLocation;
|
||||||
|
import com.drew.lang.Rational;
|
||||||
import com.drew.metadata.Directory;
|
import com.drew.metadata.Directory;
|
||||||
import com.drew.metadata.Metadata;
|
import com.drew.metadata.Metadata;
|
||||||
import com.drew.metadata.Tag;
|
import com.drew.metadata.Tag;
|
||||||
|
@ -374,8 +375,23 @@ public class MetadataHandler implements MethodChannel.MethodCallHandler {
|
||||||
Metadata metadata = ImageMetadataReader.readMetadata(is);
|
Metadata metadata = ImageMetadataReader.readMetadata(is);
|
||||||
for (ExifSubIFDDirectory directory : metadata.getDirectoriesOfType(ExifSubIFDDirectory.class)) {
|
for (ExifSubIFDDirectory directory : metadata.getDirectoriesOfType(ExifSubIFDDirectory.class)) {
|
||||||
putDescriptionFromTag(metadataMap, KEY_APERTURE, directory, ExifSubIFDDirectory.TAG_FNUMBER);
|
putDescriptionFromTag(metadataMap, KEY_APERTURE, directory, ExifSubIFDDirectory.TAG_FNUMBER);
|
||||||
putStringFromTag(metadataMap, KEY_EXPOSURE_TIME, directory, ExifSubIFDDirectory.TAG_EXPOSURE_TIME);
|
|
||||||
putDescriptionFromTag(metadataMap, KEY_FOCAL_LENGTH, directory, ExifSubIFDDirectory.TAG_FOCAL_LENGTH);
|
putDescriptionFromTag(metadataMap, KEY_FOCAL_LENGTH, directory, ExifSubIFDDirectory.TAG_FOCAL_LENGTH);
|
||||||
|
if (directory.containsTag(ExifSubIFDDirectory.TAG_EXPOSURE_TIME)) {
|
||||||
|
// TAG_EXPOSURE_TIME as a string is sometimes a ratio, sometimes a decimal
|
||||||
|
// so we explicitly request it as a rational (e.g. 1/100, 1/14, 71428571/1000000000, 4000/1000, 2000000000/500000000)
|
||||||
|
// and process it to make sure the numerator is `1` when the ratio value is less than 1
|
||||||
|
Rational rational = directory.getRational(ExifSubIFDDirectory.TAG_EXPOSURE_TIME);
|
||||||
|
long num = rational.getNumerator();
|
||||||
|
long denom = rational.getDenominator();
|
||||||
|
if (num > denom) {
|
||||||
|
metadataMap.put(KEY_EXPOSURE_TIME, rational.toSimpleString(true) + "″");
|
||||||
|
} else {
|
||||||
|
if (num != 1 && num != 0) {
|
||||||
|
rational = new Rational(1, Math.round(denom / (double) num));
|
||||||
|
}
|
||||||
|
metadataMap.put(KEY_EXPOSURE_TIME, rational.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
if (directory.containsTag(ExifSubIFDDirectory.TAG_ISO_EQUIVALENT)) {
|
if (directory.containsTag(ExifSubIFDDirectory.TAG_ISO_EQUIVALENT)) {
|
||||||
metadataMap.put(KEY_ISO, "ISO" + directory.getDescription(ExifSubIFDDirectory.TAG_ISO_EQUIVALENT));
|
metadataMap.put(KEY_ISO, "ISO" + directory.getDescription(ExifSubIFDDirectory.TAG_ISO_EQUIVALENT));
|
||||||
}
|
}
|
||||||
|
@ -463,12 +479,6 @@ public class MetadataHandler implements MethodChannel.MethodCallHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void putStringFromTag(Map<String, Object> metadataMap, String key, Directory dir, int tag) {
|
|
||||||
if (dir.containsTag(tag)) {
|
|
||||||
metadataMap.put(key, dir.getString(tag));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void putLocalizedTextFromXmp(Map<String, Object> metadataMap, String key, XMPMeta xmpMeta, String propName) throws XMPException {
|
private static void putLocalizedTextFromXmp(Map<String, Object> metadataMap, String key, XMPMeta xmpMeta, String propName) throws XMPException {
|
||||||
if (xmpMeta.doesPropertyExist(XMP_DC_SCHEMA_NS, propName)) {
|
if (xmpMeta.doesPropertyExist(XMP_DC_SCHEMA_NS, propName)) {
|
||||||
XMPProperty item = xmpMeta.getLocalizedText(XMP_DC_SCHEMA_NS, propName, XMP_GENERIC_LANG, XMP_SPECIFIC_LANG);
|
XMPProperty item = xmpMeta.getLocalizedText(XMP_DC_SCHEMA_NS, propName, XMP_GENERIC_LANG, XMP_SPECIFIC_LANG);
|
||||||
|
|
Loading…
Reference in a new issue