日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

java读取照片Exif信息到实体类

發布時間:2023/11/26 windows 33 coder
生活随笔 收集整理的這篇文章主要介紹了 java读取照片Exif信息到实体类 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

前言

1.總共讀出來了228個參數信息,但是我挑選了36個我認為比較有價值的參數,弄成了實體類
(其實是因為很多參數我看不明白是啥意思)
2.為了方便,所以實體類里我直接用中文字段了

效果圖

導入依賴

        <!-- 讀取照片元信息 -->
        <dependency>
            <groupId>com.drewnoakes</groupId>
            <artifactId>metadata-extractor</artifactId>
            <version>2.19.0</version>
        </dependency>

算法代碼

public static void main(String[] args) throws ImageProcessingException, IOException {
        File file = new File("C:\\Users\\13301\\Desktop\\漫漫星河\\IMG_1252.JPG");
        ImageExifInfoVo imageExifInfoVo = readImageExif(file);
        System.out.println(imageExifInfoVo);

    }

    /**
     * 讀取照片Exif信息
     *
     * @param file
     * @return
     * @throws ImageProcessingException
     * @throws IOException
     */
    public static ImageExifInfoVo readImageExif(File file) throws ImageProcessingException, IOException {
        ImageExifInfoVo exifInfoVo = new ImageExifInfoVo();
        Metadata metadata = JpegMetadataReader.readMetadata(file);
        boolean type = metadata.containsDirectoryOfType(GpsDirectory.class);
        Iterable<Directory> it = metadata.getDirectories();
        for (Directory d : it) {
            Collection<Tag> tags = d.getTags();
            for (Tag tag : tags) {
                String tagName = tag.getTagName();
                String description = tag.getDescription();
                switch (tagName) {
                    case "Make":
                        exifInfoVo.set廠商(description);
                        break;
                    case "Model":
                        exifInfoVo.set機型(description);
                        break;
                    case "Orientation":
                        exifInfoVo.set方向(description);
                        break;
                    case "X Resolution":
                        exifInfoVo.set水平分辨率(description);
                        break;
                    case "Y Resolution":
                        exifInfoVo.set垂直分辨率(description);
                        break;
                    case "Resolution Unit":
                        exifInfoVo.set分辨率單位(description);
                        break;
                    case "Date/Time":
                        exifInfoVo.set拍攝時間(description);
                        break;
                    case "Exposure Time":
                        exifInfoVo.set曝光時間(description);
                        break;
                    case "F-Number":
                        exifInfoVo.set光圈(description);
                        break;
                    case "Exposure Program":
                        exifInfoVo.set曝光程序(description);
                        break;
                    case "ISO Speed Ratings":
                        exifInfoVo.setISO感光度(description);
                        break;
                    case "Sensitivity Type":
                        exifInfoVo.set感光類型(description);
                        break;
                    case "Recommended Exposure Index":
                        exifInfoVo.set推薦曝光指數(description);
                        break;
                    case "Exif Version":
                        exifInfoVo.setExif版本(description);
                        break;
                    case "Components Configuration":
                        exifInfoVo.set成分構成(description);
                        break;
                    case "Shutter Speed Value":
                        exifInfoVo.set快門速度(description);
                        break;
                    case "Aperture Value":
                        exifInfoVo.set光圈值(description);
                        break;
                    case "Exposure Bias Value":
                        exifInfoVo.set曝光補償(description);
                        break;
                    case "Metering Mode":
                        exifInfoVo.set測光模式(description);
                        break;
                    case "Flash":
                        exifInfoVo.set閃光燈(description);
                        break;
                    case "Focal Length":
                        exifInfoVo.set焦距(description);
                        break;
                    case "User Comment":
                        exifInfoVo.set用戶注釋(description);
                        break;
                    case "Color Space":
                        exifInfoVo.set色域(description);
                        break;
                    case "Exif Image Width":
                        exifInfoVo.set照片寬度(description);
                        break;
                    case "Exif Image Height":
                        exifInfoVo.set照片高度(description);
                        break;
                    case "White Balance Mode":
                        exifInfoVo.set白平衡模式(description);
                        break;
                    case "Lens Model":
                        exifInfoVo.set鏡頭型號(description);
                        break;
                    case "Macro Mode":
                        exifInfoVo.set微距模式(description);
                        break;
                    case "Self Timer Delay":
                        exifInfoVo.set延時器(description);
                        break;
                    case "Quality":
                        exifInfoVo.set質量(description);
                        break;
                    case "Continuous Drive Mode":
                        exifInfoVo.set連續拍照模式(description);
                        break;
                    case "Record Mode":
                        exifInfoVo.set記錄模式(description);
                        break;
                    case "Long Focal Length":
                        exifInfoVo.set長焦距(description);
                        break;
                    case "Short Focal Length":
                        exifInfoVo.set短焦距(description);
                        break;
                    case "Max Aperture":
                        exifInfoVo.set鏡頭最大光圈(description);
                        break;
                    case "Min Aperture":
                        exifInfoVo.set鏡頭最小光圈(description);
                        break;
                    default:
                        break;
                }
            }
        }
        return exifInfoVo;
    }

實體類代碼

package cn.daenx.yhchatDemo.testApp;

import lombok.Data;

/**
 * 照片Exif信息
 *
 * @author DaenMax
 */
@Data
public class ImageExifInfoVo {
    private String 廠商;
    private String 機型;
    private String 方向;
    private String 水平分辨率;
    private String 垂直分辨率;
    private String 分辨率單位;
    private String 拍攝時間;
    private String 曝光時間;
    private String 光圈;
    private String 曝光程序;
    private String ISO感光度;
    private String 感光類型;
    private String 推薦曝光指數;
    private String Exif版本;
    private String 成分構成;
    private String 快門速度;
    private String 光圈值;
    private String 曝光補償;
    private String 測光模式;
    private String 閃光燈;
    private String 焦距;
    private String 用戶注釋;
    private String 色域;
    private String 照片寬度;
    private String 照片高度;
    private String 白平衡模式;
    private String 鏡頭型號;
    private String 微距模式;
    private String 延時器;
    private String 質量;
    private String 連續拍照模式;
    private String 記錄模式;
    private String 長焦距;
    private String 短焦距;
    private String 鏡頭最大光圈;
    private String 鏡頭最小光圈;
}

總結

以上是生活随笔為你收集整理的java读取照片Exif信息到实体类的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。