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

Last change on this file since 6168 was 6142, checked in by Don-vip, 11 years ago

see #8902 - fix compilation warnings

  • Property svn:eol-style set to native
File size: 2.5 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.tools;
3
4import java.io.File;
5import java.io.IOException;
6import java.text.ParseException;
7import java.util.Date;
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.ExifIFD0Directory;
16import com.drew.metadata.exif.ExifSubIFDDirectory;
17
18/**
19 * Read out exif file information from a jpeg file
20 * @author Imi
21 */
22public class ExifReader {
23
24 @SuppressWarnings("unchecked") public static Date readTime(File filename) throws ParseException {
25 try {
26 Metadata metadata = JpegMetadataReader.readMetadata(filename);
27 String dateStr = null;
28 OUTER:
29 for (Directory dirIt : metadata.getDirectories()) {
30 for (Tag tag : dirIt.getTags()) {
31 if (tag.getTagType() == ExifSubIFDDirectory.TAG_DATETIME_ORIGINAL /* 0x9003 */) {
32 dateStr = tag.getDescription();
33 break OUTER; // prefer this tag
34 }
35 if (tag.getTagType() == ExifIFD0Directory.TAG_DATETIME /* 0x0132 */ ||
36 tag.getTagType() == ExifSubIFDDirectory.TAG_DATETIME_DIGITIZED /* 0x9004 */) {
37 dateStr = tag.getDescription();
38 }
39 }
40 }
41 if (dateStr != null) {
42 dateStr = dateStr.replace('/', ':'); // workaround for HTC Sensation bug, see #7228
43 return DateParser.parse(dateStr);
44 }
45 } catch (ParseException e) {
46 throw e;
47 } catch (Exception e) {
48 e.printStackTrace();
49 }
50 return null;
51 }
52
53 public static Integer readOrientation(File filename) throws ParseException {
54 Integer orientation = null;
55 try {
56 final Metadata metadata = JpegMetadataReader.readMetadata(filename);
57 final Directory dir = metadata.getDirectory(ExifIFD0Directory.class);
58 orientation = dir.getInt(ExifIFD0Directory.TAG_ORIENTATION);
59 } catch (JpegProcessingException e) {
60 e.printStackTrace();
61 } catch (MetadataException e) {
62 e.printStackTrace();
63 } catch (IOException e) {
64 e.printStackTrace();
65 }
66 return orientation;
67 }
68
69}
Note: See TracBrowser for help on using the repository browser.