Example usage for org.apache.commons.imaging.formats.tiff.constants ExifTagConstants EXIF_TAG_DATE_TIME_ORIGINAL

List of usage examples for org.apache.commons.imaging.formats.tiff.constants ExifTagConstants EXIF_TAG_DATE_TIME_ORIGINAL

Introduction

In this page you can find the example usage for org.apache.commons.imaging.formats.tiff.constants ExifTagConstants EXIF_TAG_DATE_TIME_ORIGINAL.

Prototype

TagInfoAscii EXIF_TAG_DATE_TIME_ORIGINAL

To view the source code for org.apache.commons.imaging.formats.tiff.constants ExifTagConstants EXIF_TAG_DATE_TIME_ORIGINAL.

Click Source Link

Usage

From source file:org.openstreetmap.josm.plugins.mapillary.utils.ImageImportUtil.java

/**
 * @param is the input stream to read the metadata from
 * @param f the file that will be set as a field to the returned {@link MapillaryImportedImage}
 * @param defaultLL the coordinates that the image should get, if no coordinates are found in metadata
 * @return the {@link MapillaryImportedImage} with the read metadata and the given file set
 * @throws IOException if an IOException occurs while reading from the input stream
 *//*from   w ww  . ja  v a 2 s  .c  om*/
private static MapillaryImportedImage readImageFrom(final InputStream is, final File f, final LatLon defaultLL)
        throws IOException {
    Object latRef = null;
    Object lonRef = null;
    Object lat = null;
    Object lon = null;
    Object gpsDir = null;
    Object dateTime = null;
    final ImageMetadata meta;
    try {
        meta = Imaging.getMetadata(is, null);
        if (meta instanceof JpegImageMetadata) {
            final JpegImageMetadata jpegMeta = (JpegImageMetadata) meta;
            latRef = getTiffFieldValue(jpegMeta, GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF);
            lonRef = getTiffFieldValue(jpegMeta, GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF);
            lat = getTiffFieldValue(jpegMeta, GpsTagConstants.GPS_TAG_GPS_LATITUDE);
            lon = getTiffFieldValue(jpegMeta, GpsTagConstants.GPS_TAG_GPS_LONGITUDE);
            gpsDir = getTiffFieldValue(jpegMeta, GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION);
            dateTime = getTiffFieldValue(jpegMeta, ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL);
        }
    } catch (ImageReadException e) {
        // Can't read metadata from image, use defaults instead
    }

    final LatLon latLon;
    if (lat instanceof RationalNumber[] && latRef != null && lon instanceof RationalNumber[]
            && lonRef != null) {
        latLon = new LatLon(MapillaryUtils.degMinSecToDouble((RationalNumber[]) lat, latRef.toString()),
                MapillaryUtils.degMinSecToDouble((RationalNumber[]) lon, lonRef.toString()));
    } else {
        latLon = defaultLL;
    }
    final double ca;
    if (gpsDir instanceof RationalNumber) {
        ca = ((RationalNumber) gpsDir).doubleValue();
    } else {
        ca = 0;
    }
    if (dateTime == null) {
        return new MapillaryImportedImage(latLon, ca, f);
    }
    return new MapillaryImportedImage(latLon, ca, f, dateTime.toString());
}