import java.io.File;
import com.drew.imaging.ImageMetadataReader;
import com.drew.metadata.Directory;
import com.drew.metadata.Metadata;
import com.drew.metadata.exif.ExifIFD0Directory;
import com.drew.metadata.exif.ExifSubIFDDirectory;
public class TestExif {
/**
* @param args
* @throws Exception
* @throws
*/
public static void main(String[] args) throws Exception {
File imgFile = new File("F:/IMG_0538.JPG");
Metadata metadata = ImageMetadataReader.readMetadata(imgFile);
for (Directory directory : metadata.getDirectories()) {
if("ExifSubIFDDirectory".equalsIgnoreCase( directory.getClass().getSimpleName() )){
//光圈F值=镜头的焦距/镜头光圈的直径
System.out.println("光圈值: f/" + directory.getString(ExifSubIFDDirectory.TAG_FNUMBER) );
System.out.println("曝光时间: " + directory.getString(ExifSubIFDDirectory.TAG_EXPOSURE_TIME)+ "秒" );
System.out.println("ISO速度: " + directory.getString(ExifSubIFDDirectory.TAG_ISO_EQUIVALENT) );
System.out.println("焦距: " + directory.getString(ExifSubIFDDirectory.TAG_FOCAL_LENGTH) + "毫米" );
System.out.println("拍照时间: " + directory.getString(ExifSubIFDDirectory.TAG_DATETIME_ORIGINAL) );
System.out.println("宽: " + directory.getString(ExifSubIFDDirectory.TAG_EXIF_IMAGE_WIDTH) );
System.out.println("高: " + directory.getString(ExifSubIFDDirectory.TAG_EXIF_IMAGE_HEIGHT) );
}
if("ExifIFD0Directory".equalsIgnoreCase( directory.getClass().getSimpleName() )){
System.out.println("照相机制造商: " + directory.getString(ExifIFD0Directory.TAG_MAKE) );
System.out.println("照相机型号: " + directory.getString(ExifIFD0Directory.TAG_MODEL) );
System.out.println("水平分辨率: " + directory.getString(ExifIFD0Directory.TAG_X_RESOLUTION) );
System.out.println("垂直分辨率: " + directory.getString(ExifIFD0Directory.TAG_Y_RESOLUTION) );
}
}
}
}
示例输出如下:
光圈值: f/4
曝光时间: 1/500秒
ISO速度: 80
焦距: 6毫米
拍照时间: 2011:06:11 08:05:40
宽: 3648
高: 2736
照相机制造商: Canon
照相机型号: Canon PowerShot SX120 IS
水平分辨率: 180
垂直分辨率: 180
已有 0 人发表留言,猛击->> 这里<<-参与讨论
ITeye推荐