Java解析照片拿到GPS位置数据的详细步骤
Java解析照片拿到GPS位置数据的详细步骤
目录1.前提条件2.代码环境
java代码逐步解析照片拿到GPS位置数据,附上步骤讲解,附上源代码和jar包依赖
1.前提条件
第一,检查你图片是否是高清原图;第二,检查你的图片是否来自IPhone设备;第三,检查你拍照片时,是否打开了GPS;三者缺一不可
2.代码环境
A:需要的Jar包:
B:开发环境
1.maven 引入jar包2.JDK 1.83.windows OS
C:核心代码
import com.drew.imaging.jpeg.JpegMetadataReader;
import com.drew.imaging.jpeg.JpegProcessingException;
import com.drew.metadata.Directory;
import com.drew.metadata.Metadata;
import com.drew.metadata.Tag;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
public class PictureTest {
public static void readPic() {
System.out.println("开始读取图片信息...");
File jpegFile = new File("18.jpg");
Metadata metadata;
try {
metadata = JpegMetadataReader.readMetadata(jpegFile);
Iterator
while (it.hasNext()) {
Directory exif = it.next();
Iterator
while (tags.hasNext()) {
Tag tag = (Tag) tags.next();
System.out.println(tag);
}
}
System.out.println("图片信息读取完成!");
} catch (JpegProcessingException e) {
e.printStackTrace();
} catch (IOException e) {
}
}
}
D:照片信息提取结果:
开始读取图片信息...[JPEG] Compression Type - Baseline[JPEG] Data Precision - 8 bits[JPEG] Image Height - 3456 pixels[JPEG] Image Width - 4608 pixels[JPEG] Number of Components - 3[JPEG] Component 1 - Y component: Quantization table 0, Sampling factors 2 horiz/2 vert[JPEG] Component 2 - Cb component: Quantization table 1, Sampling factors 1 horiz/1 vert[JPEG] Component 3 - Cr component: Quantization table 1, Sampling factors 1 horiz/1 vert[Exif IFD0] Image Width - 4608 pixels[Exif IFD0] Image Height - 3456 pixels[Exif IFD0] Make - OnePlus[Exif IFD0] Model - ONEPLUS A6010[Exif IFD0] Orientation - Right side, top (Rotate 90 CW)[Exif IFD0] X Resolution - 72 dots per inch[Exif IFD0] Y Resolution - 72 dots per inch[Exif IFD0] Resolution Unit - Inch[Exif IFD0] Date/Time - 2019:09:03 10:41:29[Exif IFD0] YCbCr Positioning - Center of pixel array[Exif SubIFD] Exposure Time - 1/1445 sec[Exif SubIFD] F-Number - f/1.7[Exif SubIFD] Exposure Program - Program normal[Exif SubIFD] ISO Speed Ratings - 100[Exif SubIFD] Exif Version - 2.20[Exif SubIFD] Date/Time Original - 2019:09:03 10:41:29[Exif SubIFD] Date/Time Digitized - 2019:09:03 10:41:29[Exif SubIFD] Components Configuration - YCbCr[Exif SubIFD] Shutter Speed Value - 1/1444 sec[Exif SubIFD] Aperture Value - f/1.7[Exif SubIFD] Brightness Value - 3.9[Exif SubIFD] Exposure Bias Value - 0 EV[Exif SubIFD] Max Aperture Value - f/1.7[Exif SubIFD] Metering Mode - Center weighted average[Exif SubIFD] White Balance - Unknown[Exif SubIFD] Flash - Flash did not fire, auto[Exif SubIFD] Focal Length - 4.3 mm[Exif SubIFD] Sub-Sec Time - 260556[Exif SubIFD] Sub-Sec Time Original - 260556[Exif SubIFD] Sub-Sec Time Digitized - 260556[Exif SubIFD] FlashPix Version - 1.00[Exif SubIFD] Color Space - sRGB[Exif SubIFD] Exif Image Width - 4608 pixels[Exif SubIFD] Exif Image Height - 3456 pixels[Exif SubIFD] Sensing Method - (Not defined)[Exif SubIFD]http:// Scene Type - Directly photographed image[Exif SubIFD] Exposure Mode - Auto exposure[Exif SubIFD] White Balance Mode - Auto white balance[Exif SubIFD] Focal Length 35 - 25 mm[Exif SubIFD] Scene Capture Type - Standard[Interoperability] Interoperability Index - Recommended Exif Interoperability Rules (ExifR98)[Interoperability] Interoperability Version - 1.00[GPS] GPS Latitude Ref - N[GPS] GPS Latitude - 30° 18' 31.31"[GPS] GPS Longitude Ref - E[GPS] GPS Longitude - 120° 20' 36.31"[GPS] GPS Altitude Ref - Sea level[GPS] GPS Altitude - 0 metres[GPS] GPS Time-Stamp - 02:41:28.000 UTC[GPS] GPS Processing Method - CELLID[GPS] GPS Date Stamp - 2019:09:03[Exif Thumbnail] Exif Image Width - 320 pixels[Exif Thumbnail] Exif Image Height - 240 pixels[Exif Thumbnail] Compression - JPEG (old-style)[Exif Thumbnail] Orientation - Right side, top (Rotate 90 CW)[Exif Thumbnail] X Resolution - 72 dots per inch[Exif Thumbnail] Y Resolution - 72 dots per inch[Exif Thumbnail] Resolution Unit - Inch[Exif Thumbnail] Thumbnail Offset - 1104 bytes[Exif Thumbnail] Thumbnail Length - 38449 bytes[XMP] XMP Value Count - 5[Huffman] Number of Tables - 4 Huffman tables[File] File Name - 18.jpg[File] File Size - 7027316 bytes[File] File Modified Date - 星期二 九月 03 10:55:39 +08:00 2019图片信息读取完成!
有意义的信息截取:
[GPS] GPS Latitude Ref - N [GPS] GPS Latitude - 30° 18clScArlQ' 31.31" 维度[GPS] GPS Longitude Ref - E[GPS] GPS Longitude - 120° 20' 36.31" 经度[GPS] GPS Altitude Ref - Sea level[GPS] GPS Altitude - 0 metres[GPS] GPS Time-Stamp - 02:41:28.000 UTC 拍摄时间[GPS] GPS Processing Method - CELLID[GPS] GPS Date Stamp - 2019:09:03 拍摄时间
[Exif IFD0] Make - OnePlus 设备信息[Exif IFD0] Model - ONEPLUS A6010 设备型号
根据经纬度查询结果:
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~