Read exif using metadata extraction
metadata extraction version : 2.3.1
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Iterator;
import com.drew.imaging.jpeg.JpegProcessingException;
import com.drew.metadata.Directory;
import com.drew.metadata.Metadata;
import com.drew.metadata.exif.ExifDirectory;
import com.drew.metadata.exif.ExifReader;
public class EXIFReader {
public static void printExif(String fileName) throws FileNotFoundException {
File f = new File(fileName);
try {
ExifReader er = new ExifReader(f);
Metadata exif = er.extract();
Iterator itr = exif.getDirectoryIterator();
while (itr.hasNext()) {
Directory directory = (Directory) itr.next();
System.out.println("EXIF版本:" + directory.getString(ExifDirectory.TAG_EXIF_VERSION));
System.out.println("相機品牌:" + directory.getString(ExifDirectory.TAG_MAKE));
System.out.println("像機號碼:" + directory.getString(ExifDirectory.TAG_MODEL));
System.out.println("光 圈 值:" + directory.getString(ExifDirectory.TAG_FNUMBER));
System.out.println("快 門:" + directory.getString(ExifDirectory.TAG_EXPOSURE_TIME));
System.out.println("感 光 度:" + directory.getString(ExifDirectory.TAG_ISO_EQUIVALENT));
System.out.println("軟 件:" + directory.getString(ExifDirectory.TAG_SOFTWARE));
System.out.println("原始拍攝時間:" + directory.getString(ExifDirectory.TAG_DATETIME_ORIGINAL));
System.out.println("數字化時間:" + directory.getString(ExifDirectory.TAG_DATETIME_DIGITIZED));
System.out.println("方 向:" + directory.getString(ExifDirectory.TAG_ORIENTATION));
System.out.println("圖片寬度:" + directory.getString(ExifDirectory.TAG_EXIF_IMAGE_WIDTH));
System.out.println("圖片高度:" + directory.getString(ExifDirectory.TAG_EXIF_IMAGE_HEIGHT));
System.out.println("水平分辨率:" + directory.getString(ExifDirectory.TAG_X_RESOLUTION));
System.out.println("垂直分辨率:" + directory.getString(ExifDirectory.TAG_Y_RESOLUTION));
System.out.println("垂直分辨率:" + directory.getString(ExifDirectory.TAG_EXPOSURE_BIAS));
break;
}
} catch (JpegProcessingException e) {
System.err.println("not jpeg file");
}
}
}