Example usage for org.apache.commons.imaging.formats.jpeg JpegImageMetadata findEXIFValue

List of usage examples for org.apache.commons.imaging.formats.jpeg JpegImageMetadata findEXIFValue

Introduction

In this page you can find the example usage for org.apache.commons.imaging.formats.jpeg JpegImageMetadata findEXIFValue.

Prototype

public TiffField findEXIFValue(final TagInfo tagInfo) 

Source Link

Usage

From source file:com.cons.gps2exif.exif.ReadMetaData.java

private static void printTagValue(JpegImageMetadata jpegMetadata, TagInfo tagInfo) throws ImageReadException {
    try {/*from   w  w  w  .  j a  v  a  2 s . c o  m*/
        // ---------------------------------
        // KEY PART: Extract EXIF by TagInfo
        // if you use findEXIFValueWithExactMatch,
        // the method throws NullPointerException when the provided tag does not present in the
        // metadata
        // ---------------------------------
        TiffField field = jpegMetadata.findEXIFValue(tagInfo);

        if (field != null) {
            // get actual stored value in metadata
            Object value = field.getValue();
            System.out.println(tagInfo.name + ": " + toString(value));
        }
    } catch (NullPointerException e) {
    }
}

From source file:com.moorestudio.seniorimageprocessing.SeniorSorter.java

public void getTimestampData() throws ImageReadException, IOException, ParseException {
    int numImages = imageData.size();
    for (File image : imageData.keySet()) {
        IImageMetadata metadata = getMetadata(image);
        if (metadata instanceof JpegImageMetadata) {
            JpegImageMetadata md = (JpegImageMetadata) metadata;
            String dateTime = md.findEXIFValue(TiffTagConstants.TIFF_TAG_DATE_TIME).getStringValue();

            //if the dateTime is null, then throw an error
            if (dateTime == null || dateTime.isEmpty()) {
                throw new ImageReadException("Images do not contain the EXIF date information.");
            } else {
                //convert from EXIF format to a date
                SimpleDateFormat dateParser = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss");
                imageData.put(image, dateParser.parse(dateTime).getTime());
            }/*  w  ww . j a  va2  s  .c  o m*/

            //update the gui
            parent.addProgress((.125 / parent.numThreads) / numImages);
        } else {
            throw new ImageReadException("Images do not contain the EXIF date information.");
        }
    }
}