zoukankan      html  css  js  c++  java
  • java读取照片信息 获取照片拍摄时的经纬度

    项目结构

    源码:ImageInfo.zip

    第一步:添加需要的架包metadate-extractor.jar

      架包下载地址:https://code.google.com/p/metadata-extractor/downloads/list

      或者去Maven仓库下载 http://search.maven.org/#search%7Cga%7C1%7Cmetadata-extractor

    第二步:编写解析代码

     1 package com.drew.metadata;  
     2 import java.io.File;  
     3 
     4 import com.drew.imaging.ImageMetadataReader;  
     5 import com.drew.imaging.ImageProcessingException;  
     6 /**
     7  * java读取照片信息
     8  */
     9 public class SampleUsage{
    10     public static void main(String[] args) throws Exception, Exception{  
    11         File file = new File("E:\带有地理位置的图片.jpg");  
    12         printImageTags(file);
    13     } 
    14     /** 
    15      * 读取照片里面的信息 
    16      */ 
    17     private static void printImageTags(File file) throws ImageProcessingException, Exception{  
    18         Metadata metadata = ImageMetadataReader.readMetadata(file);  
    19         for (Directory directory : metadata.getDirectories()) {  
    20             for (Tag tag : directory.getTags()) {  
    21                 String tagName = tag.getTagName();  //标签名
    22                 String desc = tag.getDescription(); //标签信息
    23                 if (tagName.equals("Image Height")) {  
    24                     System.out.println("图片高度: "+desc);
    25                 } else if (tagName.equals("Image Width")) {  
    26                     System.out.println("图片宽度: "+desc);
    27                 } else if (tagName.equals("Date/Time Original")) {  
    28                     System.out.println("拍摄时间: "+desc);
    29                 }else if (tagName.equals("GPS Latitude")) {  
    30                     System.err.println("纬度 : "+desc);
    31 //                    System.err.println("纬度(度分秒格式) : "+pointToLatlong(desc));
    32                 } else if (tagName.equals("GPS Longitude")) {  
    33                     System.err.println("经度: "+desc);
    34 //                    System.err.println("经度(度分秒格式): "+pointToLatlong(desc));
    35                 }
    36             }  
    37         }  
    38     }  
    39     /** 
    40      * 经纬度格式  转换为  度分秒格式 ,如果需要的话可以调用该方法进行转换
    41      * @param point 坐标点 
    42      * @return 
    43      */ 
    44     public static String pointToLatlong (String point ) {  
    45         Double du = Double.parseDouble(point.substring(0, point.indexOf("°")).trim());  
    46         Double fen = Double.parseDouble(point.substring(point.indexOf("°")+1, point.indexOf("'")).trim());  
    47         Double miao = Double.parseDouble(point.substring(point.indexOf("'")+1, point.indexOf(""")).trim());  
    48         Double duStr = du + fen / 60 + miao / 60 / 60 ;  
    49         return duStr.toString();  
    50     }  
    51 }
    52  


     

  • 相关阅读:
    Comparison of Performance Testing Tools
    软件测试两年总结
    利用FSO生成QTP测试报告
    Web 2.0 再思考(三)「搭讪」是需要理由的
    脑子里想的是A,嘴巴上说的是B,实际上做的是C,幻想前景远大的是D,可真正赚钱的恰恰却是E
    东莞镇区实力排名榜
    狂籌資計畫
    转载:日剧和韩剧的区别
    Web 2.0 再思考(一)「关系」才是重点
    炒股
  • 原文地址:https://www.cnblogs.com/tfgzs/p/3833673.html
Copyright © 2011-2022 走看看