Java解析照片拿到GPS位置數(shù)據(jù)的詳細步驟
Java代碼逐步解析照片拿到GPS位置數(shù)據(jù),附上步驟講解,附上源代碼和jar包依賴
1.前提條件
第一,檢查你圖片是否是高清原圖;
第二,檢查你的圖片是否來自IPhone設(shè)備;
第三,檢查你拍照片時,是否打開了GPS;
三者缺一不可
2.代碼環(huán)境
A:需要的Jar包:
<dependency> <groupId>com.drewnoakes</groupId> <artifactId>metadata-extractor</artifactId> <version>2.12.0</version> </dependency>
B:開發(fā)環(huán)境
1.maven 引入jar包
2.JDK 1.8
3.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<Directory> it = metadata.getDirectories().iterator(); while (it.hasNext()) { Directory exif = it.next(); Iterator<Tag> tags = exif.getTags().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:照片信息提取結(jié)果:
開始讀取圖片信息...
[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] 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
圖片信息讀取完成!
有意義的信息截?。?/p>
[GPS] GPS Latitude Ref - N
[GPS] GPS Latitude - 30° 18' 31.31" 維度
[GPS] GPS Longitude Ref - E
[GPS] GPS Longitude - 120° 20' 36.31" 經(jīng)度
[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 設(shè)備信息
[Exif IFD0] Model - ONEPLUS A6010 設(shè)備型號
根據(jù)經(jīng)緯度查詢結(jié)果:
原文鏈接和源碼下載地址 原文鏈接:https://www.cnblogs.com/haha12/p/11451009.html
GPS位置查詢鏈接:http://www.gpsspg.com/maps.htm
經(jīng)緯度格式轉(zhuǎn)化鏈接:http://www.minigps.net/fc.html
代碼下載地址:[源碼地址]http://xiazai.jb51.net/202203/yuanma/ImageInfoScratch_jb51.rar
到此這篇關(guān)于Java解析照片拿到GPS位置數(shù)據(jù)的文章就介紹到這了,更多相關(guān)Java照片GPS內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
在Java中Collection的一些常用方法總結(jié)
今天給大家?guī)淼闹R是關(guān)于Java的,文章圍繞著Java中Collection的一些常用方法展開,文中有非常詳細的介紹及代碼示例,需要的朋友可以參考下2021-06-06Spring Boot 將yyyy-MM-dd格式的文本字符串直接轉(zhuǎn)換為LocalDateTime出現(xiàn)的問題
這篇文章主要介紹了Spring Boot 將yyyy-MM-dd格式的文本字符串直接轉(zhuǎn)換為LocalDateTime出現(xiàn)的問題,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-09-09