亲宝软件园·资讯

展开

Java照片GPS

西湖边的码农 人气:0

Java代码逐步解析照片拿到GPS位置数据,附上步骤讲解,附上源代码和jar包依赖

1.前提条件

第一,检查你图片是否是高清原图;
第二,检查你的图片是否来自IPhone设备;
第三,检查你拍照片时,是否打开了GPS;
三者缺一不可

2.代码环境

A:需要的Jar包:

 <dependency>
            <groupId>com.drewnoakes</groupId>
            <artifactId>metadata-extractor</artifactId>
            <version>2.12.0</version>
 </dependency>

B:开发环境

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:照片信息提取结果:

开始读取图片信息...
[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
图片信息读取完成!

有意义的信息截取:

[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 IFD0] Make - OnePlus              设备信息
[Exif IFD0] Model - ONEPLUS A6010   设备型号

根据经纬度查询结果:

原文链接和源码下载地址 原文链接:https://www.cnblogs.com/haha12/p/11451009.html
GPS位置查询链接:http://www.gpsspg.com/maps.htm
经纬度格式转化链接:http://www.minigps.net/fc.html
代码下载地址:[源码地址]http://xiazai.jb51.net/202203/yuanma/ImageInfoScratch_jb51.rar

加载全部内容

相关教程
猜你喜欢
用户评论