source: josm/trunk/src/org/openstreetmap/josm/tools/ExifReader.java@ 4595

Last change on this file since 4595 was 4241, checked in by bastiK, 13 years ago

applied #5605 - Geotagged image viewer should rotate images according to EXIF orientation tag (patch by m.zdila, some modifications)

  • Property svn:eol-style set to native
File size: 2.1 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.tools;
3
4import java.io.File;
5import java.text.ParseException;
6import java.util.Date;
7import java.util.Iterator;
8
9import com.drew.imaging.jpeg.JpegMetadataReader;
10import com.drew.imaging.jpeg.JpegProcessingException;
11import com.drew.metadata.Directory;
12import com.drew.metadata.Metadata;
13import com.drew.metadata.MetadataException;
14import com.drew.metadata.Tag;
15import com.drew.metadata.exif.ExifDirectory;
16
17/**
18 * Read out exif file information from a jpeg file
19 * @author Imi
20 */
21public class ExifReader {
22
23 @SuppressWarnings("unchecked") public static Date readTime(File filename) throws ParseException {
24 Date date = null;
25 try {
26 Metadata metadata = JpegMetadataReader.readMetadata(filename);
27 for (Iterator<Directory> dirIt = metadata.getDirectoryIterator(); dirIt.hasNext();) {
28 for (Iterator<Tag> tagIt = dirIt.next().getTagIterator(); tagIt.hasNext();) {
29 Tag tag = tagIt.next();
30 if (tag.getTagType() == 0x9003)
31 return DateParser.parse(tag.getDescription());
32 if (tag.getTagType() == 0x132 || tag.getTagType() == 0x9004)
33 date = DateParser.parse(tag.getDescription());
34 }
35 }
36 } catch (ParseException e) {
37 throw e;
38 } catch (Exception e) {
39 e.printStackTrace();
40 }
41 return date;
42 }
43
44 @SuppressWarnings("unchecked") public static Integer readOrientation(File filename) throws ParseException {
45 Integer orientation = null;
46 try {
47 final Metadata metadata = JpegMetadataReader.readMetadata(filename);
48 final Directory dir = metadata.getDirectory(ExifDirectory.class);
49 orientation = dir.getInt(ExifDirectory.TAG_ORIENTATION);
50 } catch (JpegProcessingException e) {
51 e.printStackTrace();
52 } catch (MetadataException e) {
53 e.printStackTrace();
54 }
55 return orientation;
56 }
57
58}
Note: See TracBrowser for help on using the repository browser.