<dependency>
<groupId>com.drewnoakes</groupId>
<artifactId>metadata-extractor</artifactId>
</dependency>
public static void main(String[] args) throws Exception {
File mFile = new File("/Users/mac/Desktop/WechatIMG185.jpeg");
Metadata metadata = ImageMetadataReader.readMetadata(mFile);
// 获取所有项的信息
Iterable<Directory> directoryIterable = metadata.getDirectories();
if (directoryIterable != null) {
Iterator<Directory> directoryIterator = directoryIterable.iterator();
while (directoryIterator.hasNext()) {
Directory directory = directoryIterator.next();
Collection<Tag> tags = directory.getTags();
for (Tag tag : tags) {
// System.out.println(tag.getDescription());
System.out.println(tag);
}
}
// 取具体某一项的信息
Iterable<ExifSubIFDDirectory> exifSubIFDDirectoryIterable = metadata.getDirectoriesOfType(ExifSubIFDDirectory.class);
if (exifSubIFDDirectoryIterable != null) {
Iterator<ExifSubIFDDirectory> subIFDDirectoryIterator = exifSubIFDDirectoryIterable.iterator();
if (subIFDDirectoryIterator != null && subIFDDirectoryIterator.hasNext()) {
ExifSubIFDDirectory dr = subIFDDirectoryIterator.next();
if (dr.containsTag(ExifSubIFDDirectory.TAG_USER_COMMENT)) {
System.out.println(dr.getDescription(ExifSubIFDDirectory.TAG_USER_COMMENT));
}
}
}
}
输出如下:
[JPEG] Compression Type - Baseline
[JPEG] Data Precision - 8 bits
[JPEG] Image Height - 4032 pixels
[JPEG] Image Width - 3024 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 - none
[JFIF] X Resolution - 72 dots
[JFIF] Y Resolution - 72 dots
[JFIF] Thumbnail Width Pixels - 0
[JFIF] Thumbnail Height Pixels - 0
[Exif IFD0] Make - Yiruikecorp
[Exif IFD0] Model - foodie
[Exif IFD0] Orientation - Top, left side (Horizontal / normal)
[Exif IFD0] X Resolution - 72 dots per inch
[Exif IFD0] Y Resolution - 72 dots per inch
[Exif IFD0] Resolution Unit - Inch
[Exif IFD0] YCbCr Positioning - Center of pixel array
[Exif SubIFD] Exif Version - 2.21
[Exif SubIFD] Date/Time Digitized - 2019:07:04 15:49:15
[Exif SubIFD] Components Configuration - YCbCr
[Exif SubIFD] User Comment - plain_02,-1
[Exif SubIFD] FlashPix Version - 1.00
[Exif SubIFD] Color Space - sRGB
[Exif SubIFD] Exif Image Width - 3024 pixels
[Exif SubIFD] Exif Image Height - 4032 pixels
[Exif SubIFD] Scene Capture Type - Standard
[Exif Thumbnail] Compression - JPEG (old-style)
[Exif Thumbnail] X Resolution - 72 dots per inch
[Exif Thumbnail] Y Resolution - 72 dots per inch
[Exif Thumbnail] Resolution Unit - Inch
[Exif Thumbnail] Thumbnail Offset - 394 bytes
[Exif Thumbnail] Thumbnail Length - 10125 bytes
[XMP] XMP Value Count - 1
[Photoshop] Caption Digest - 212 29 140 217 143 0 178 4 233 128 9 152 236 248 66 126
[Huffman] Number of Tables - 4 Huffman tables
[File Type] Detected File Type Name - JPEG
[File Type] Detected File Type Long Name - Joint Photographic Experts Group
[File Type] Detected MIME Type - image/jpeg
[File Type] Expected File Name Extension - jpg
[File] File Name - WechatIMG185.jpeg
[File] File Size - 2911336 bytes
[File] File Modified Date - 星期四 七月 04 15:50:35 +08:00 2019
plain_02,-1