1. 程式人生 > >java 獲取圖片的exif資訊

java 獲取圖片的exif資訊

網上很多這類方法都沒法用,自己探索了一下。

maven工程匯入jar包

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

程式碼如下:

import com.drew.imaging.ImageMetadataReader;
import com.drew.metadata.Directory;
import com.drew.metadata.Metadata;
import com.drew.metadata.Tag;

import java.io.File;

public class Test {

    public static void main(String[] args) {

        //包含EXIF資訊的圖片地址
        File jpegFile = new File("/XXXX/XXX/XXXX.jpg");
        
        try{
            Metadata metadata = ImageMetadataReader.readMetadata(jpegFile);
            for (Directory directory : metadata.getDirectories()) {
                for (Tag tag : directory.getTags()) {
                    System.out.println(tag);
                }
            }
        }catch (Exception e){

        }
    }
}

  結果如下:

[JPEG] Compression Type - Baseline
[JPEG] Data Precision - 8 bits
[JPEG] Image Height - 3260 pixels
[JPEG] Image Width - 4890 pixels
[JPEG] Number of Components - 3
[JPEG] Component 1 - Y component: Quantization table 0, Sampling factors 1 horiz/1 vert
[JPEG] Component 2 - Cb component: Quantization table 1, Sampling factors 1 horiz/1 vert
[JPEG] Component 3 - Cr component: Quantization table 1, Sampling factors 1 horiz/1 vert
[JFIF] Version - 1.1
[JFIF] Resolution Units - inch
[JFIF] X Resolution - 300 dots
[JFIF] Y Resolution - 300 dots
[JFIF] Thumbnail Width Pixels - 0
[JFIF] Thumbnail Height Pixels - 0
[Exif IFD0] Image Width - 5568 pixels
[Exif IFD0] Image Height - 3712 pixels
[Exif IFD0] Bits Per Sample - 8 8 8 bits/component/pixel
[Exif IFD0] Photometric Interpretation - RGB
[Exif IFD0] Image Description - Foto LaPresse - Fabio Ferrari
14 07 2018 San Pietroburgo ( Russia )
Sport
Russia 2018 - Coppa del Mondo FIFA - Belgio vs Inghilterra - Finale 3-4 posto - Stadio Saint-Petersburg.
Nella foto: Thomas Meunier esulta dopo il gol 1-0


Photo LaPresse - Fabio Ferrari
July 14, 2018 Saint-Petersburg ( Russia Federation )
sport
Russia 2018 - FIFA World Cup - Belgium vs England - Play-off for third place - Saint-Petersburg stadium.
in the pic: Thomas Meunier celebrates after goal 1-0
[Exif IFD0] Make - NIKON CORPORATION
[Exif IFD0] Model - NIKON D5
[Exif IFD0] Orientation - Top, left side (Horizontal / normal)
[Exif IFD0] Samples Per Pixel - 3 samples/pixel
[Exif IFD0] X Resolution - 300 dots per inch
[Exif IFD0] Y Resolution - 300 dots per inch
[Exif IFD0] Resolution Unit - Inch
[Exif IFD0] Software - Adobe Photoshop CS6 (Macintosh) (PHP JPEG Metadata Toolkit v1.12)
[Exif IFD0] Date/Time - 2018:07:14 17:26:38
[Exif IFD0] Artist - Fabio Ferrari/LaPresse
[Exif IFD0] White Point - 313/1000 329/1000
[Exif IFD0] Primary Chromaticities - 64/100 33/100 21/100 71/100 15/100 6/100
[Exif IFD0] YCbCr Coefficients - 299/1000 587/1000 114/1000
[Exif IFD0] YCbCr Positioning - Datum point
[Exif IFD0] Copyright - LaPresse
[Exif SubIFD] Exposure Time - 1/1250 sec
[Exif SubIFD] F-Number - f/4.5
[Exif SubIFD] Exposure Program - Manual control
[Exif SubIFD] ISO Speed Ratings - 800
[Exif SubIFD] Sensitivity Type - Recommended Exposure Index
[Exif SubIFD] Recommended Exposure Index - 800
[Exif SubIFD] Exif Version - 2.31
[Exif SubIFD] Date/Time Original - 2018:07:14 16:02:47
[Exif SubIFD] Date/Time Digitized - 2018:07:14 16:02:47
[Exif SubIFD] Unknown tag (0x9010) - +00:00
[Exif SubIFD] Unknown tag (0x9011) - +00:00
[Exif SubIFD] Unknown tag (0x9012) - +00:00
[Exif SubIFD] Components Configuration - YCbCr
[Exif SubIFD] Compressed Bits Per Pixel - 4 bits/pixel
[Exif SubIFD] Shutter Speed Value - 1/1249 sec
[Exif SubIFD] Aperture Value - f/4.5
[Exif SubIFD] Exposure Bias Value - 0 EV
[Exif SubIFD] Max Aperture Value - f/2.8
[Exif SubIFD] Metering Mode - Multi-segment
[Exif SubIFD] White Balance - Unknown
[Exif SubIFD] Flash - Flash did not fire
[Exif SubIFD] Focal Length - 200 mm
[Exif SubIFD] User Comment - 
[Exif SubIFD] Sub-Sec Time - 04
[Exif SubIFD] Sub-Sec Time Original - 04
[Exif SubIFD] Sub-Sec Time Digitized - 04
[Exif SubIFD] FlashPix Version - 1.00
[Exif SubIFD] Color Space - Undefined
[Exif SubIFD] Exif Image Width - 4890 pixels
[Exif SubIFD] Exif Image Height - 3260 pixels
[Exif SubIFD] Sensing Method - One-chip color area sensor
[Exif SubIFD] File Source - 3 0 0 0 (unable to formulate description)
[Exif SubIFD] Scene Type - 1 0 0 0 (unable to formulate description)
[Exif SubIFD] CFA Pattern - [Red,Green][Green,Blue]
[Exif SubIFD] Custom Rendered - Normal process
[Exif SubIFD] Exposure Mode - Manual exposure
[Exif SubIFD] White Balance Mode - Auto white balance
[Exif SubIFD] Focal Length 35 - 200 mm
[Exif SubIFD] Scene Capture Type - Standard
[Exif SubIFD] Gain Control - Low gain up
[Exif SubIFD] Contrast - None
[Exif SubIFD] Saturation - None
[Exif SubIFD] Sharpness - Hard
[Exif SubIFD] Subject Distance Range - Unknown
[Exif SubIFD] Gamma - 2.2
[Interoperability] Interoperability Index - Unknown (R03)
[Interoperability] Interoperability Version - 1.00
[GPS] GPS Version ID - 2.300
[Exif Thumbnail] Compression - JPEG (old-style)
[Exif Thumbnail] X Resolution - 300 dots per inch
[Exif Thumbnail] Y Resolution - 300 dots per inch
[Exif Thumbnail] Resolution Unit - Inch
[Exif Thumbnail] Thumbnail Offset - 1897 bytes
[Exif Thumbnail] Thumbnail Length - 8015 bytes
[ICC Profile] Profile Size - 560
[ICC Profile] CMM Type - ADBE
[ICC Profile] Version - 2.1.0
[ICC Profile] Class - Display Device
[ICC Profile] Color space - RGB 
[ICC Profile] Profile Connection Space - XYZ 
[ICC Profile] Profile Date/Time - 1999:06:03 00:00:00
[ICC Profile] Signature - acsp
[ICC Profile] Primary Platform - Apple Computer, Inc.
[ICC Profile] Device manufacturer - none
[ICC Profile] XYZ values - 0.964 1 0.825
[ICC Profile] Tag Count - 10
[ICC Profile] Copyright - Copyright 1999 Adobe Systems Incorporated
[ICC Profile] Profile Description - Adobe RGB (1998)
[ICC Profile] Media White Point - (0.9505, 1, 1.0891)
[ICC Profile] Media Black Point - (0, 0, 0)
[ICC Profile] Red TRC - 0.0085908
[ICC Profile] Green TRC - 0.0085908
[ICC Profile] Blue TRC - 0.0085908
[ICC Profile] Red Colorant - (0.6097, 0.3111, 0.0195)
[ICC Profile] Green Colorant - (0.2053, 0.6257, 0.0609)
[ICC Profile] Blue Colorant - (0.1492, 0.0632, 0.7446)
[Photoshop] Caption Digest - 211 209 60 128 55 245 166 88 186 109 76 145 251 27 121 188
[Photoshop] Print Info 2 - [233 values]
[Photoshop] Print Style - [557 values]
[Photoshop] Resolution Info - 300x300 DPI
[Photoshop] Print Scale - Centered, Scale 1.0
[Photoshop] Background Color - 0 0 255 255 255 255 255 255 0 0
[Photoshop] Global Angle - 30
[Photoshop] Global Altitude - 30
[Photoshop] Print Flags - 0 0 0 0 0 0 0 0 1
[Photoshop] Print Flags Information - 0 1 0 0 0 0 0 0 0 2
[Photoshop] Color Halftoning Information - [72 values]
[Photoshop] Color Transfer Functions - [112 values]
[Photoshop] Grid and Guides Information - 0 0 0 1 0 0 2 64 0 0 2 64 0 0 0 0
[Photoshop] URL List - 0
[Photoshop] Slices - _FF56790 (0,0,3260,4890) 1 Slices
[Photoshop] Pixel Aspect Ratio - 1.0
[Photoshop] Seed Number - 3
[Photoshop] Thumbnail Data - JpegRGB, 160x107, Decomp 51360 bytes, 1572865 bpp, 8015 bytes
[Photoshop] Version Info - 1 (Adobe Photoshop, Adobe Photoshop CS6) 1
[Photoshop] JPEG Quality - 11 (Maximum), Standard format, 3 scans
[Photoshop] Copyright Flag - No
[IPTC] Application Record Version - 2
[IPTC] Caption/Abstract - Foto LaPresse - Fabio Ferrari
14 07 2018 San Pietroburgo ( Russia )
Sport
Russia 2018 - Coppa del Mondo FIFA - Belgio vs Inghilterra - Finale 3-4 posto - Stadio Saint-Petersburg.
Nella foto: Thomas Meunier esulta dopo il gol 1-0


Photo LaPresse - Fabio Ferrari
July 14, 2018 Saint-Petersburg ( Russia Federation )
sport
Russia 2018 - FIFA World Cup - Belgium vs England - Play-off for third place - Saint-Petersburg stadium.
in the pic: Thomas Meunier celebrates after goal 1-0
[IPTC] Caption Writer/Editor - 
[IPTC] Headline - Russia 2018 - Coppa del Mondo FIFA - Belgio vs Inghilterra - Finale 3-4 posto
[IPTC] Special Instructions - 
[IPTC] By-line - Fabio Ferrari/LaPresse
[IPTC] By-line Title - 
[IPTC] Credit - LAPRESSE
[IPTC] Source - LaPresse
[IPTC] Object Name - Russia 2018 - Coppa del Mondo FIFA - Belgio vs Inghilterra - Fin
[IPTC] Date Created - 2018:07:14
[IPTC] City - San Pietroburgo
[IPTC] Province/State - 
[IPTC] Country/Primary Location Name - Russia
[IPTC] Original Transmission Reference - 
[IPTC] Category - cal
[IPTC] Copyright Notice - LaPresse
[IPTC] Keywords - FIFA WORLD CUP 2018;COPPA DEL MONDO;CAMPIONATO MONDIALE DI CALCIO;MONDIALI RUSSIA 2018;21ESIMA EDIZIONE;FINALE 3-4 POSTO;NAZIONALE BELGA;NAZIONALE INGLESE
[Huffman] Number of Tables - 4 Huffman tables
[File Type] Detected File Type Name - JPEG
[File Type] Detected File Type Long Name - Joint Photographic Experts Group
[File Type] Detected MIME Type - image/jpeg
[File Type] Expected File Name Extension - jpg
[File] File Name - 20180714_09511.jpg
[File] File Size - 2941570 bytes
[File] File Modified Date - 星期四 八月 16 15:37:52 +08:00 2018