IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> Java知识库 -> SpringBoot项目获取图片信息 -> 正文阅读

[Java知识库]SpringBoot项目获取图片信息

第一步:引入依赖

<!-- 图片地理信息依赖 -->
<dependency>
    <groupId>com.drewnoakes</groupId>
    <artifactId>metadata-extractor</artifactId>
    <version>2.11.0</version>
</dependency>

第二步:编写代码,获取信息

import com.drew.imaging.ImageMetadataReader;
import com.drew.imaging.ImageProcessingException;
import com.drew.metadata.Directory;
import com.drew.metadata.Metadata;
import com.drew.metadata.Tag;
import com.hkwl.hkboot.smp.common.Ret;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;


/**
 * @Description:
 * @Author Be.insighted
 * @Date 2022/4/26 17:29
 */
@RestController
@Slf4j
public class ReadPictureInfoController {

    @GetMapping("picture/info")
    private Ret getPictureInfo() throws Exception {
        printImageTags(new File("D://1.jpg"));
        return Ret.success();
    }


    /**
     * 读取照片里面的信息
     */
    private static void printImageTags(File file) throws ImageProcessingException, Exception {
        Metadata metadata = ImageMetadataReader.readMetadata(file);
        for (Directory directory : metadata.getDirectories()) {
            for (Tag tag : directory.getTags()) {
                String tagName = tag.getTagName();  //标签名
                log.error("标签名: " + tagName);
                String desc = tag.getDescription(); //标签信息
                if (tagName.equals("Image Height")) {
                    System.out.println("图片高度: " + desc);
                } else if (tagName.equals("Image Width")) {
                    System.out.println("图片宽度: " + desc);
                } else if (tagName.equals("Date/Time Original")) {
                    System.out.println("拍摄时间: " + desc);
                } else if (tagName.equals("GPS Latitude")) {
                    System.err.println("纬度 : " + desc);
                    System.err.println("纬度(度分秒格式) : "+pointToLatlong(desc));
                } else if (tagName.equals("GPS Longitude")) {
                    System.err.println("经度: " + desc);
                    System.err.println("经度(度分秒格式): "+pointToLatlong(desc));
                }
            }
        }
    }

    /**
     * 经纬度格式  转换为  度分秒格式 ,如果需要的话可以调用该方法进行转换
     *
     * @param point 坐标点
     * @return
     */
    public static String pointToLatlong(String point) {
        Double du = Double.parseDouble(point.substring(0, point.indexOf("°")).trim());
        Double fen = Double.parseDouble(point.substring(point.indexOf("°") + 1, point.indexOf("'")).trim());
        Double miao = Double.parseDouble(point.substring(point.indexOf("'") + 1, point.indexOf("\"")).trim());
        Double duStr = du + fen / 60 + miao / 60 / 60;
        return duStr.toString();
    }

}

标签项:

2022-04-26 19:28:31.010 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Compression Type
2022-04-26 19:28:31.010 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Data Precision
2022-04-26 19:28:31.010 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Image Height
图片高度: 4344 pixels
2022-04-26 19:28:31.011 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Image Width
图片宽度: 5792 pixels
2022-04-26 19:28:31.011 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Number of Components
2022-04-26 19:28:31.011 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Component 1
2022-04-26 19:28:31.011 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Component 2
2022-04-26 19:28:31.011 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Component 3
2022-04-26 19:28:31.011 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Image Width
图片宽度: 5792 pixels
2022-04-26 19:28:31.011 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Model
2022-04-26 19:28:31.012 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Image Height
图片高度: 4344 pixels
2022-04-26 19:28:31.012 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Orientation
2022-04-26 19:28:31.012 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Date/Time
2022-04-26 19:28:31.012 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: YCbCr Positioning
2022-04-26 19:28:31.012 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Resolution Unit
2022-04-26 19:28:31.012 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: X Resolution
2022-04-26 19:28:31.012 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Y Resolution
2022-04-26 19:28:31.012 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Make
2022-04-26 19:28:31.012 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Unknown tag (0x9aaa)
2022-04-26 19:28:31.013 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: ISO Speed Ratings
2022-04-26 19:28:31.019 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Exposure Program
2022-04-26 19:28:31.019 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: F-Number
2022-04-26 19:28:31.019 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Exposure Time
2022-04-26 19:28:31.020 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Unknown tag (0x9999)
2022-04-26 19:28:31.024 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Sensing Method
2022-04-26 19:28:31.024 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Unknown tag (0x8895)
2022-04-26 19:28:31.024 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Sub-Sec Time Digitized
2022-04-26 19:28:31.024 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Sub-Sec Time Original
2022-04-26 19:28:31.024 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Sub-Sec Time
2022-04-26 19:28:31.024 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Focal Length
2022-04-26 19:28:31.024 ERROR 纬度 : 0° 0' 0"
纬度(度分秒格式) : 0.0
经度: 0° 0' 0"
经度(度分秒格式): 0.0
20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Flash
2022-04-26 19:28:31.024 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: White Balance
2022-04-26 19:28:31.024 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Metering Mode
2022-04-26 19:28:31.025 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Scene Capture Type
2022-04-26 19:28:31.025 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Focal Length 35
2022-04-26 19:28:31.025 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Max Aperture Value
2022-04-26 19:28:31.025 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Date/Time Digitized
2022-04-26 19:28:31.025 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Exposure Bias Value
2022-04-26 19:28:31.025 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Exif Image Height
2022-04-26 19:28:31.025 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: White Balance Mode
2022-04-26 19:28:31.025 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Date/Time Original
拍摄时间: 2022:04:24 18:23:22
2022-04-26 19:28:31.026 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Brightness Value
2022-04-26 19:28:31.026 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Exif Image Width
2022-04-26 19:28:31.026 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Exposure Mode
2022-04-26 19:28:31.026 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Aperture Value
2022-04-26 19:28:31.026 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Components Configuration
2022-04-26 19:28:31.026 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Color Space
2022-04-26 19:28:31.026 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Scene Type
2022-04-26 19:28:31.026 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Shutter Speed Value
2022-04-26 19:28:31.026 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Exif Version
2022-04-26 19:28:31.027 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: FlashPix Version
2022-04-26 19:28:31.027 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Interoperability Index
2022-04-26 19:28:31.027 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Interoperability Version
2022-04-26 19:28:31.027 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: GPS Latitude Ref
2022-04-26 19:28:31.027 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: GPS Latitude
2022-04-26 19:28:31.027 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: GPS Longitude Ref
2022-04-26 19:28:31.027 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: GPS Longitude
2022-04-26 19:28:31.028 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: GPS Altitude Ref
2022-04-26 19:28:31.029 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: GPS Altitude
2022-04-26 19:28:31.029 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: GPS Time-Stamp
2022-04-26 19:28:31.029 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: GPS Processing Method
2022-04-26 19:28:31.029 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: GPS Date Stamp
2022-04-26 19:28:31.029 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Thumbnail Offset
2022-04-26 19:28:31.029 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Orientation
2022-04-26 19:28:31.029 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Thumbnail Length
2022-04-26 19:28:31.030 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Compression
2022-04-26 19:28:31.031 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Resolution Unit
2022-04-26 19:28:31.031 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: X Resolution
2022-04-26 19:28:31.031 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Y Resolution
2022-04-26 19:28:31.031 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Exif Image Height
2022-04-26 19:28:31.031 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Exif Image Width
2022-04-26 19:28:31.031 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: XMP Value Count
2022-04-26 19:28:31.031 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Number of Tables
2022-04-26 19:28:31.031 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Detected File Type Name
2022-04-26 19:28:31.031 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Detected File Type Long Name
2022-04-26 19:28:31.031 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Detected MIME Type
2022-04-26 19:28:31.031 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: Expected File Name Extension
2022-04-26 19:28:31.032 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: File Name
2022-04-26 19:28:31.032 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: File Size
2022-04-26 19:28:31.032 ERROR 20456 --- [io-10087-exec-6] c.h.h.s.c.ReadPictureInfoController ? ? ?: 标签名: File Modified Date

  Java知识库 最新文章
计算距离春节还有多长时间
系统开发系列 之WebService(spring框架+ma
springBoot+Cache(自定义有效时间配置)
SpringBoot整合mybatis实现增删改查、分页查
spring教程
SpringBoot+Vue实现美食交流网站的设计与实
虚拟机内存结构以及虚拟机中销毁和新建对象
SpringMVC---原理
小李同学: Java如何按多个字段分组
打印票据--java
上一篇文章      下一篇文章      查看所有文章
加:2022-04-28 11:39:48  更:2022-04-28 11:42:50 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/24 2:40:55-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码