概述
本站之前开发了图片的一系列操作和查看工具,包括属性查看,图片转换等等,依赖了别人的一些API,目前需要改成自己的API。
来查看这些上图的图片文件对应的属性:
依赖Jar包,metadata-extractor
Maven 引入:
com.drewnoakes
metadata-extractor
2.12.0
Gradle Groovy DSLimplementation 'com.drewnoakes:metadata-extractor:2.12.0'
Gradle Kotlin DSLcompile("com.drewnoakes:metadata-extractor:2.12.0")
图片属性查看代码//获取该图片文件
File file = new File("/Users/zhoubocheng/Downloads/IMG_2294.JPG");
Metadata metadata = JpegMetadataReader.readMetadata(file);
//输出所有附加属性数据
for (Directory directory : metadata.getDirectories()) {
System.out.println("属性组:" + directory.getName());
for (Tag tag : directory.getTags()) {
String kv = String.format("%s = %s",tag.getTagName(),tag.getDescription());
System.out.println(kv);
}
}
查看图片EXIF信息
注意需要手机或者相机等直接拍照的图片,剪切图,PS图等等部分信息是缺失的。//获取EXIF信息,用直接相机或者手机拍出来的图片来做获取,剪切图或者操作过裁剪大部分信息是读取不到的
System.out.println("++++++++++++++++++ EXIF ++++++++++++++++++++");
ExifIFD0Directory exif = metadata.getFirstDirectoryOfType(ExifIFD0Directory.class);
if(null != exif){
//循环输出
exif.getTags().forEach(System.out::println);
if(exif.containsTag(ExifIFD0Directory.TAG_MAKE)){
System.out.println("Make:" + exif.getDescription(ExifIFD0Directory.TAG_MAKE));
}
}
System.out.println("ExifSubIFDDirectory:");
Directory exifSub = metadata.getFirstDirectoryOfType(ExifSubIFDDirectory.class);
if(null != exifSub){
//循环输出
exifSub.getTags().forEach(System.out::println);
}
System.out.println("ExifInteropDirectory:");
Directory exifInterop = metadata.getFirstDirectoryOfType(ExifInteropDirectory.class);
if(null != exifInterop){
//循环输出
exifInterop.getTags().forEach(System.out::println);
}
System.out.println("ExifThumbnailDirectory:");
Directory exifThumbnail = metadata.getFirstDirectoryOfType(ExifThumbnailDirectory.class);
if(null != exifThumbnail){
//循环输出
exifThumbnail.getTags().forEach(System.out::println);
}
整体内容输出:属性组:JPEG
Compression Type = Baseline
Data Precision = 8 bits
Image Height = 3024 pixels
Image Width = 4032 pixels
Number of Components = 3
Component 1 = Y component: Quantization table 0, Sampling factors 2 horiz/2 vert
Component 2 = Cb component: Quantization table 1, Sampling factors 1 horiz/1 vert
Component 3 = Cr component: Quantization table 1, Sampling factors 1 horiz/1 vert
属性组:Exif IFD0
Orientation = Top, left side (Horizontal / normal)
X Resolution = 72 dots per inch
Y Resolution = 72 dots per inch
Resolution Unit = Inch
YCbCr Positioning = Center of pixel array
属性组:Exif SubIFD
Exif Version = 2.21
Components Configuration = YCbCr
FlashPix Version = 1.00
Color Space = sRGB
Exif Image Width = 4032 pixels
Exif Image Height = 3024 pixels
Scene Capture Type = Standard
属性组:Exif Thumbnail
Compression = JPEG (old-style)
X Resolution = 72 dots per inch
Y Resolution = 72 dots per inch
Resolution Unit = Inch
Thumbnail Offset = 286 bytes
Thumbnail Length = 9220 bytes
属性组:ICC Profile
Profile Size = 548
CMM Type = appl
Version = 4.0.0
Class = Display Device
Color space = RGB
Profile Connection Space = XYZ
Profile Date/Time = 2017:07:07 13:22:32
Signature = acsp
Primary Platform = Apple Computer, Inc.
Device manufacturer = APPL
XYZ values = 0.964 1 0.825
Tag Count = 10
Profile Description = Display P3
Copyright = Copyright Apple Inc., 2017
Media White Point = (0.9505, 1, 1.0891)
Red Colorant = (0.5151, 0.2412, 65536)
Green Colorant = (0.292, 0.6922, 0.0419)
Blue Colorant = (0.1571, 0.0666, 0.7841)
Red TRC = para (0x70617261): 32 bytes
Chromatic Adaptation = sf32 (0x73663332): 44 bytes
Blue TRC = para (0x70617261): 32 bytes
Green TRC = para (0x70617261): 32 bytes
属性组:Huffman
Number of Tables = 4 Huffman tables
属性组:File
File Name = IMG_2294.JPG
File Size = 2853337 bytes
File Modified Date = 星期三 七月 24 10:54:38 +08:00 2019
++++++++++++++++++ EXIF ++++++++++++++++++++
[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
ExifSubIFDDirectory:
[Exif SubIFD] Exif Version - 2.21
[Exif SubIFD] Components Configuration - YCbCr
[Exif SubIFD] FlashPix Version - 1.00
[Exif SubIFD] Color Space - sRGB
[Exif SubIFD] Exif Image Width - 4032 pixels
[Exif SubIFD] Exif Image Height - 3024 pixels
[Exif SubIFD] Scene Capture Type - Standard
ExifInteropDirectory:
ExifThumbnailDirectory:
[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 - 286 bytes
[Exif Thumbnail] Thumbnail Length - 9220 bytes
本文主题:
如果本文对你有帮助,那么请你赞助我,让我更有激情的写下去,帮助更多的人。
¥我需要走的更远,点击我 赞助。
如果还有疑问,点击我加群,为你提供最好的解答。
最后
以上就是糟糕大白为你收集整理的java exif 怎么获取属性_Java 获取图片属性、获取图片EXIF属性操作方法[metadata-extractor]...的全部内容,希望文章能够帮你解决java exif 怎么获取属性_Java 获取图片属性、获取图片EXIF属性操作方法[metadata-extractor]...所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复