符合EXIFJPEG標(biāo)準(zhǔn)的圖片,除了記錄圖片壓縮數(shù)據(jù)之外,在存儲(chǔ)了拍攝參數(shù),其中包括拍攝時(shí)GPS參數(shù)信息,因此,可以利用程序從EXIF元數(shù)據(jù)信息中解析提取GPS位置信息。
1. Java讀取EXIF信息
Metadata Extractor是一個(gè)開源的Java用具解析圖片元數(shù)據(jù)的庫,可以用來識(shí)別JPEG圖片的EXIF信息,具體信息參見:http://code.google.com/p/metadata-extractor/
下載地址為:http://code.google.com/p/metadata-extractor/downloads/list
- import java.io.File;
- import java.io.IOException;
- import java.util.Collection;
-
- import com.drew.imaging.ImageProcessingException;
- import com.drew.imaging.jpeg.JpegMetadataReader;
- import com.drew.metadata.Metadata;
- import com.drew.metadata.MetadataException;
- import com.drew.metadata.Tag;
- import com.drew.metadata.exif.GpsDirectory;
-
- public class Main {
- public static void main(String[] args) throws ImageProcessingException,
- IOException, MetadataException {
- File jpegFile = new File("01.jpg");
- Metadata meta = JpegMetadataReader.readMetadata(jpegFile);
- GpsDirectory gps = meta.getDirectory(GpsDirectory.class);
- if (gps != null) {
- Collection<Tag> tags = gps.getTags();
- for (Tag tag : tags) {
- System.out.println(tag);
- }
- }
- }
- }
輸出結(jié)果如下:
- [GPS] GPS Version ID - 2.200
- [GPS] GPS Latitude Ref - N
- [GPS] GPS Latitude - 40.0° 0.0' 16.999999999993065"
- [GPS] GPS Longitude Ref - E
- [GPS] GPS Longitude - 116.0° 22.0' 44.99999999998636"
- [GPS] GPS Altitude Ref - Below sea level
- [GPS] GPS Altitude - 0 metres
- [GPS] GPS Time-Stamp - 8:29:45 UTC
- [GPS] GPS Processing Method - 65 83 67 73 73 0 0 0
- [GPS] GPS Date Stamp - 2014:06:16
2. 在Android中提取GPS信息
Android API提供解析EXIF,具體可以參見這里:
http://blog.csdn.net/whucyl/article/details/9103171
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)
點(diǎn)擊舉報(bào)。