Java获取照片EXIF信息

目前最简单易用的EXIF信息处理的Java包是Drew Noakes写的metadata-extractor,你可以直接从http://www.drewnoakes.com/code/exif/ 下载该项目的最新版本包括其源码。
这里用的是2.6.4版本,代码如下:
/*
 * @(#)Main.java	       Project:Hello
 * Date-Time:2013-10-16 下午5:24:06
 *
 * Copyright (c) 2013 CFuture09, Institute of Software, 
 * Guangdong Ocean University, Zhanjiang, GuangDong, China.
 * All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import java.io.File;
import java.util.Iterator;

import com.drew.imaging.jpeg.JpegMetadataReader;
import com.drew.metadata.Directory;
import com.drew.metadata.Metadata;
import com.drew.metadata.Tag;

public class Main {
	public static void main(String[] args) throws Exception {
		File jpegFile = new File("C:\\Users\\wzh\\Desktop\\QQ图片20131016170038.jpg");
		Metadata metadata = JpegMetadataReader.readMetadata(jpegFile);
		Iterable<Directory> a = metadata.getDirectories();
		for (Directory directory : a) {
			Iterator<Tag> tag = directory.getTags().iterator();
			while(tag.hasNext()) {
				System.out.println(tag.next());
			}
		}
	}
}


打印出来的信息如下:
[Jpeg] Compression Type - Baseline
[Jpeg] Data Precision - 8 bits
[Jpeg] Image Height - 706 pixels
[Jpeg] Image Width - 784 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
[Jfif] Version - 1.1
[Jfif] Resolution Units - inch
[Jfif] X Resolution - 96 dots
[Jfif] Y Resolution - 96 dots

你可能感兴趣的:(java)