获取一个图片的信息demo

利用jar包获取的demo案例


前言

这里是获取图片的相关信息小demo,仅供参考。
参考链接


一、引入相关jar包

直接引入metadata-extractor-2.8.1和xmpcore-5.1.2的jar包。

二、代码内容

public class PicInfo {
    public static void main(String[] args) {
        readPicInfo("C:\\Users\\dell\\Desktop\\R-C.jpg");
    }
    public static HashMap<String,Object> readPicInfo(String filePath){
        HashMap<String,Object> map = new HashMap<String, Object>();
        File jpegFile = new File(filePath);
        Metadata metadata;
        try {
            metadata = JpegMetadataReader.readMetadata(jpegFile);
            Iterator<Directory> iterator = metadata.getDirectories().iterator();
            while (iterator.hasNext()){
                Directory next = iterator.next();
                Iterator<Tag> tags = next.getTags().iterator();
                while (tags.hasNext()){
                    Tag tag = tags.next();
                    System.out.println(tag.getTagName()+"-----"+tag.getDescription());
                }
            }
            System.out.println("第二部分的案例内容");
            Metadata metadata1 = ImageMetadataReader.readMetadata(jpegFile);
            Iterator<Directory> iterator1 = metadata1.getDirectories().iterator();
            while (iterator1.hasNext()){
                Directory next = iterator1.next();
                Iterator<Tag> iterator2 = next.getTags().iterator();
                while (iterator2.hasNext()){
                    Tag next1 = iterator2.next();
                    System.out.println(next1.getTagName()+"----next2----"+next1.getDescription());
                }
            }
        } catch (JpegProcessingException e) {
            e.printStackTrace();
        } catch (ImageProcessingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return map;
    }
}

三、代码运行结果

Compression Type-----Baseline
Data Precision-----8 bits
Image Height-----1080 pixels
Image Width-----1920 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
Version-----1.1
Resolution Units-----none
X Resolution-----1 dot
Y Resolution-----1 dot
Thumbnail Width Pixels-----0
Thumbnail Height Pixels-----0
Number of Tables-----4 Huffman tables
File Name-----R-C.jpg
File Size-----289024 bytes
File Modified Date-----星期六 七月 10 08:22:51 +08:00 2021
第二部分的案例内容
Compression Type----next2----Baseline
Data Precision----next2----8 bits
Image Height----next2----1080 pixels
Image Width----next2----1920 pixels
Number of Components----next2----3
Component 1----next2----Y component: Quantization table 0, Sampling factors 2 horiz/2 vert
Component 2----next2----Cb component: Quantization table 1, Sampling factors 1 horiz/1 vert
Component 3----next2----Cr component: Quantization table 1, Sampling factors 1 horiz/1 vert
Version----next2----1.1
Resolution Units----next2----none
X Resolution----next2----1 dot
Y Resolution----next2----1 dot
Thumbnail Width Pixels----next2----0
Thumbnail Height Pixels----next2----0
Number of Tables----next2----4 Huffman tables
Detected File Type Name----next2----JPEG
Detected File Type Long Name----next2----Joint Photographic Experts Group
Detected MIME Type----next2----image/jpeg
Expected File Name Extension----next2----jpg
File Name----next2----R-C.jpg
File Size----next2----289024 bytes
File Modified Date----next2----星期六 七月 10 08:22:51 +08:00 2021

Process finished with exit code 0

由此可见两者的结果差不多都是这些,但是我没有获取到GPS的相关信息,或许是因为我这个图片没有GPS相关信息,搞不懂,后续尝试多测试测试,或者有知道的小伙伴可以告知一下,不胜感激。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值