Last change
on this file since 196 was 182, checked in by imi, 17 years ago |
- fixed geoimage reader to priorize the entry of DateTimeOriginal and DateTimeDigitalized over DateTime
|
File size:
1.2 KB
|
Line | |
---|
1 | package org.openstreetmap.josm.tools;
|
---|
2 |
|
---|
3 | import java.io.File;
|
---|
4 | import java.text.ParseException;
|
---|
5 | import java.util.Date;
|
---|
6 | import java.util.Iterator;
|
---|
7 |
|
---|
8 | import com.drew.imaging.jpeg.JpegMetadataReader;
|
---|
9 | import com.drew.metadata.Directory;
|
---|
10 | import com.drew.metadata.Metadata;
|
---|
11 | import com.drew.metadata.Tag;
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * Read out exif file information from a jpeg file
|
---|
15 | * @author Imi
|
---|
16 | */
|
---|
17 | public class ExifReader {
|
---|
18 |
|
---|
19 | @SuppressWarnings("unchecked") public static Date readTime(File filename) throws ParseException {
|
---|
20 | Date date = null;
|
---|
21 | try {
|
---|
22 | Metadata metadata = JpegMetadataReader.readMetadata(filename);
|
---|
23 | for (Iterator<Directory> dirIt = metadata.getDirectoryIterator(); dirIt.hasNext();) {
|
---|
24 | for (Iterator<Tag> tagIt = dirIt.next().getTagIterator(); tagIt.hasNext();) {
|
---|
25 | Tag tag = tagIt.next();
|
---|
26 | if (tag.getTagType() == 0x9003)
|
---|
27 | return DateParser.parse(tag.getDescription());
|
---|
28 | if (tag.getTagType() == 0x132 || tag.getTagType() == 0x9004)
|
---|
29 | date = DateParser.parse(tag.getDescription());
|
---|
30 | }
|
---|
31 | }
|
---|
32 | } catch (ParseException e) {
|
---|
33 | throw e;
|
---|
34 | } catch (Exception e) {
|
---|
35 | e.printStackTrace();
|
---|
36 | }
|
---|
37 | return date;
|
---|
38 | }
|
---|
39 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.