首页>代码>java读取带有地理位置照片的信息>/java读取照片信息/src/com/drew/metadata/SampleUsage.java
package com.drew.metadata;  
import java.io.File;  

import com.drew.imaging.ImageMetadataReader;  
import com.drew.imaging.ImageProcessingException;  
/**
 * java读取照片信息
 */
public class SampleUsage{
	public static void main(String[] args) throws Exception, Exception{  
        File file = new File("E:\\带有地理位置的图片.jpg");  
        printImageTags(file);
    } 
    /** 
     * 读取照片里面的信息 
     */ 
    private static void printImageTags(File file) throws ImageProcessingException, Exception{  
    	Metadata metadata = ImageMetadataReader.readMetadata(file);  
        for (Directory directory : metadata.getDirectories()) {  
            for (Tag tag : directory.getTags()) {  
                String tagName = tag.getTagName();  //标签名
                String desc = tag.getDescription(); //标签信息
                if (tagName.equals("Image Height")) {  
                	System.out.println("图片高度: "+desc);
                } else if (tagName.equals("Image Width")) {  
                	System.out.println("图片宽度: "+desc);
                } else if (tagName.equals("Date/Time Original")) {  
                	System.out.println("拍摄时间: "+desc);
                }else if (tagName.equals("GPS Latitude")) {  
                	System.err.println("纬度 : "+desc);
//                	System.err.println("纬度(度分秒格式) : "+pointToLatlong(desc));
                } else if (tagName.equals("GPS Longitude")) {  
                	System.err.println("经度: "+desc);
//                	System.err.println("经度(度分秒格式): "+pointToLatlong(desc));
                }
            }  
        }  
    }  
    /** 
     * 经纬度格式  转换为  度分秒格式 ,如果需要的话可以调用该方法进行转换
     * @param point 坐标点 
     * @return 
     */ 
    public static String pointToLatlong (String point ) {  
        Double du = Double.parseDouble(point.substring(0, point.indexOf("°")).trim());  
        Double fen = Double.parseDouble(point.substring(point.indexOf("°")+1, point.indexOf("'")).trim());  
        Double miao = Double.parseDouble(point.substring(point.indexOf("'")+1, point.indexOf("\"")).trim());  
        Double duStr = du + fen / 60 + miao / 60 / 60 ;  
        return duStr.toString();  
    }  
}
 
最近下载更多
woodjs  LV1 2022年6月9日
cheng99521  LV1 2022年4月8日
c1zqwer  LV1 2022年1月8日
苏木焱  LV2 2021年8月20日
南彧先生  LV9 2021年7月26日
chayzzz  LV2 2021年7月9日
qiuqiuwangwang  LV2 2021年5月11日
maki666  LV1 2021年4月14日
Monster  LV1 2021年3月25日
dongzhan  LV12 2020年12月7日
最近浏览更多
woodjs  LV1 2022年6月9日
陈小灏  LV14 2022年5月25日
包呼和  LV10 2022年5月11日
Mywang  LV4 2022年4月20日
jwz jwz  LV13 2022年4月19日
cheng99521  LV1 2022年4月8日
c1zqwer  LV1 2022年1月8日
sswert  LV2 2021年11月22日
苏木焱  LV2 2021年8月20日
陈齐尧  LV11 2021年8月16日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友