前言
1.总共读出来了228个参数信息,但是我挑选了36个我认为比较有价值的参数,弄成了实体类
(其实是因为很多参数我看不明白是啥意思)
2.为了方便,所以实体类里我直接用中文字段了
效果图
导入依赖
<!-- 读取照片元信息 -->
<dependency>
<groupId>com.drewnoakes</groupId>
<artifactId>metadata-extractor</artifactId>
<version>2.19.0</version>
</dependency>
算法代码
public static void main(String[] args) throws ImageProcessingException, IOException {
File file = new File("C:\\Users\\13301\\Desktop\\漫漫星河\\IMG_1252.JPG");
ImageExifInfoVo imageExifInfoVo = readImageExif(file);
System.out.println(imageExifInfoVo);
}
/**
* 读取照片Exif信息
*
* @param file
* @return
* @throws ImageProcessingException
* @throws IOException
*/
public static ImageExifInfoVo readImageExif(File file) throws ImageProcessingException, IOException {
ImageExifInfoVo exifInfoVo = new ImageExifInfoVo();
Metadata metadata = JpegMetadataReader.readMetadata(file);
boolean type = metadata.containsDirectoryOfType(GpsDirectory.class);
Iterable<Directory> it = metadata.getDirectories();
for (Directory d : it) {
Collection<Tag> tags = d.getTags();
for (Tag tag : tags) {
String tagName = tag.getTagName();
String description = tag.getDescription();
switch (tagName) {
case "Make":
exifInfoVo.set厂商(description);
break;
case "Model":
exifInfoVo.set机型(description);
break;
case "Orientation":
exifInfoVo.set方向(description);
break;
case "X Resolution":
exifInfoVo.set水平分辨率(description);
break;
case "Y Resolution":
exifInfoVo.set垂直分辨率(description);
break;
case "Resolution Unit":
exifInfoVo.set分辨率单位(description);
break;
case "Date/Time":
exifInfoVo.set拍摄时间(description);
break;
case "Exposure Time":
exifInfoVo.set曝光时间(description);
break;
case "F-Number":
exifInfoVo.set光圈(description);
break;
case "Exposure Program":
exifInfoVo.set曝光程序(description);
break;
case "ISO Speed Ratings":
exifInfoVo.setISO感光度(description);
break;
case "Sensitivity Type":
exifInfoVo.set感光类型(description);
break;
case "Recommended Exposure Index":
exifInfoVo.set推荐曝光指数(description);
break;
case "Exif Version":
exifInfoVo.setExif版本(description);
break;
case "Components Configuration":
exifInfoVo.set成分构成(description);
break;
case "Shutter Speed Value":
exifInfoVo.set快门速度(description);
break;
case "Aperture Value":
exifInfoVo.set光圈值(description);
break;
case "Exposure Bias Value":
exifInfoVo.set曝光补偿(description);
break;
case "Metering Mode":
exifInfoVo.set测光模式(description);
break;
case "Flash":
exifInfoVo.set闪光灯(description);
break;
case "Focal Length":
exifInfoVo.set焦距(description);
break;
case "User Comment":
exifInfoVo.set用户注释(description);
break;
case "Color Space":
exifInfoVo.set色域(description);
break;
case "Exif Image Width":
exifInfoVo.set照片宽度(description);
break;
case "Exif Image Height":
exifInfoVo.set照片高度(description);
break;
case "White Balance Mode":
exifInfoVo.set白平衡模式(description);
break;
case "Lens Model":
exifInfoVo.set镜头型号(description);
break;
case "Macro Mode":
exifInfoVo.set微距模式(description);
break;
case "Self Timer Delay":
exifInfoVo.set延时器(description);
break;
case "Quality":
exifInfoVo.set质量(description);
break;
case "Continuous Drive Mode":
exifInfoVo.set连续拍照模式(description);
break;
case "Record Mode":
exifInfoVo.set记录模式(description);
break;
case "Long Focal Length":
exifInfoVo.set长焦距(description);
break;
case "Short Focal Length":
exifInfoVo.set短焦距(description);
break;
case "Max Aperture":
exifInfoVo.set镜头最大光圈(description);
break;
case "Min Aperture":
exifInfoVo.set镜头最小光圈(description);
break;
default:
break;
}
}
}
return exifInfoVo;
}
实体类代码
package cn.daenx.yhchatDemo.testApp;
import lombok.Data;
/**
* 照片Exif信息
*
* @author DaenMax
*/
@Data
public class ImageExifInfoVo {
private String 厂商;
private String 机型;
private String 方向;
private String 水平分辨率;
private String 垂直分辨率;
private String 分辨率单位;
private String 拍摄时间;
private String 曝光时间;
private String 光圈;
private String 曝光程序;
private String ISO感光度;
private String 感光类型;
private String 推荐曝光指数;
private String Exif版本;
private String 成分构成;
private String 快门速度;
private String 光圈值;
private String 曝光补偿;
private String 测光模式;
private String 闪光灯;
private String 焦距;
private String 用户注释;
private String 色域;
private String 照片宽度;
private String 照片高度;
private String 白平衡模式;
private String 镜头型号;
private String 微距模式;
private String 延时器;
private String 质量;
private String 连续拍照模式;
private String 记录模式;
private String 长焦距;
private String 短焦距;
private String 镜头最大光圈;
private String 镜头最小光圈;
}