Java获取图片的EXIF信息(简单实现)

 首先说说什么是EXIF信息?

可交换图像文件格式(英语:Exchangeable image file format,官方简称Exif), 是专门为数码相机的照片设定的文件格式,可以记录数码照片的属性信息和拍摄数据。EXIF可以附加于JPEG、TIFF、RIFF等文件之中,为其增加有关数码相机拍摄信息的内容和索引图或图像处理软件的版本信息。

 我们右键图片,点击属性,里面的详细信息就是这张图片的EXIF信息。

https://drewnoakes.com/code/exif/   官方链接 可下载最新版本和源码

代码实现

创建maven工程,添加依赖

<dependency>
      <groupId>com.drewnoakes</groupId>
      <artifactId>metadata-extractor</artifactId>
      <version>2.8.1</version>
</dependency>

java代码

public static void main(String[] args) {
        //自己的图片路径
        File file = new File("D:" + File.separator + "photo" + File.separator + "1.jpg");
        try {
            Metadata metadata = ImageMetadataReader.readMetadata(file);
            for (Directory directory: metadata.getDirectories()){
                for (Tag tag : directory.getTags()){
//                    System.out.format("[%s] - %s = %s",
//                            directory.getName(), tag.getTagName(), tag.getDescription());
                    System.out.println(tag);
                }
                if (directory.hasErrors()) {
                    for (String error : directory.getErrors()) {
                        System.err.format("ERROR: %s", error);
                    }
                }
            }
        } catch (Exception e) {
            System.out.println(e.toString());
        }
    }

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值