Reading GPS Data From EXIF Using Groovy

废话不说了,直接上code吧:

import com.drew.imaging.jpeg.*;
import com.drew.metadata.*;
import com.drew.metadata.exif.*;

file = new File("sample.jpg");
meta = JpegMetadataReader.readMetadata(file);

gpsdir = meta.getDirectory(GpsDirectory.class);
lat = gpsdir.getRationalArray(GpsDirectory.TAG_GPS_LATITUDE);
lon = gpsdir.getRationalArray(GpsDirectory.TAG_GPS_LONGITUDE);
lats = lat[0].doubleValue() + lat[1].doubleValue()/60 + lat[2].doubleValue()/3600;
lons = lon[0].doubleValue() + lon[1].doubleValue()/60 + lon[2].doubleValue()/3600;
println(lats);
println(lons);

metadata-extractor似乎是现在惟一的读取exif信息的java库。在ivy中可以添加这样一个依赖:

<dependency org="com.drewnoakes" name="metadata-extractor" rev="2.4.0-beta-1" conf="runtime"/>
This entry was written by Sunng , posted on Monday October 05 2009at 11:10 pm , filed under 手艺 and tagged , , . Bookmark the permalink . Post a comment below or leave a trackback: Trackback URL.

2 Responses to “Reading GPS Data From EXIF Using Groovy”

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word