Java get photo-related properties

Source: Internet
Author: User

Package Test;import Java.io.file;import Java.util.Iterator; Import Com.drew.imaging.jpeg.jpegmetadatareader;import Com.drew.metadata.directory;import Com.drew.metadata.metadata;import Com.drew.metadata.tag;import com.drew.metadata.exif.ExifDirectory; /** * Test EXIF information for reading pictures */public class Exiftester {public     static void Main (string[] args) throws Exception {         File J Pegfile = new File ("e:\\ picture \\2.JPG");         Metadata Metadata = Jpegmetadatareader.readmetadata (jpegfile);         Directory exif = Metadata.getdirectory (exifdirectory.class);         Iterator tags = exif.gettagiterator ();         while (Tags.hasnext ()) {             tag tag = (tag) tags.next ();             SYSTEM.OUT.PRINTLN (tag);}}}     

Jar Package Required: metadata-extractor-2.3.0

run result [Exif] Thumbnail Image Width-2896Pixels[exif] Thumbnail Image Height-1944Pixels[exif] Bits Per Sample-8 8 8 bits/component/Pixel[exif] make-NIKON Corporation[exif] Model-NIKON D200[exif] Orientation-Top, left side (Horizontal/Normal) [Exif] Samples Per Pixel-3 samples/Pixel[exif] X Resolution-300dots per inch[exif] Y Resolution-300dots per inch[exif] Resolution Unit-inch[exif] Software-Adobe Photoshop CC (Windows) [Exif] Date/time-2014:05:04 13:17:26[Exif] YCbCr positioning-Datum Point[exif] Exposure time-1/640Sec[exif] F-number-f4.5[Exif] Exposure Program-Aperture Priority[exif] ISO speed ratings-125[EXIF] EXIF Version-2.21[Exif] Date/time original-2014:05:02 15:00:40[Exif] Date/time digitized-2014:05:02 15:00:40[Exif] Components Configuration-ycbcr[exif] Compressed Bits Per Pixel-4 bits/Pixel[exif] Shutter speed Value-1/639Sec[exif] Aperture Value-F4.5[Exif] Exposure Bias Value-2/3Ev[exif] Max Aperture Value-F4.4[Exif] metering Mode-Center weighted average[exif] light Source-Unknown[exif] Flash-Flash did not fire[exif] Focal Length-70.0Mm[exif] User Comment-Xcb[exif] Sub-sec Time-90[Exif] Sub-sec Time Original-90[Exif] Sub-sec Time Digitized-90[Exif] FlashPix Version-1.00[Exif] Color Space-Srgb[exif] Exif Image Width-1944Pixels[exif] Exif Image Height-1944Pixels[exif] Sensing Method-one-chip color area Sensor[exif] File Source-Digital still Camera (DSC) [Exif] Scene Type-Directly photographed image[exif] CFA Pattern-0 2 0 2 1 0 2 1[Exif] Custom Rendered-Normal process[exif] Exposure Mode-Auto exposure[exif] White Balance-Auto White balance[exif] Digital Zoom Ratio-1[Exif] Focal Length35-1mm[exif] Scene Capture Type-Standard[exif] Gain Control-None[exif] Contrast-None[exif] Saturation-High saturation[exif] sharpness-Hard[exif] Subject Distance Range-Unknown
Get the required data package test;  Import Java.io.file;import java.util.Iterator; Import Com.drew.imaging.jpeg.jpegmetadatareader;import Com.drew.metadata.directory;import  Com.drew.metadata.metadata;import com.drew.metadata.exif.ExifDirectory; /** * Test EXIF information for reading pictures * @author Winter Lau */public class Picexif {public static void main (string[] args) throws Exce         ption {File Jpegfile = new File ("e:\\ picture \\2.JPG");         Metadata Metadata = Jpegmetadatareader.readmetadata (jpegfile);         Directory exif = Metadata.getdirectory (Exifdirectory.class);        Iterator tags = exif.gettagiterator ();        while (Tags.hasnext ()) {//System.out.println (Tags.next ());        Iterator s = exif.gettagiterator ();        while (S.hasnext ()) {//System.out.println (S.next ()); }//} if (Exif.containstag (Exifdirectory.tag_model)) {System.out.println ( "Camera Model:" +exif.getdescription (Exifdirectory.tag_model)); } if (Exif.containstag (exifdirectory.tag_exposure_time)) {System.out.println ("Exposure Time:" +exif.getdescription (Ex           Ifdirectory.tag_exposure_time)); } if (Exif.containstag (exifdirectory.tag_datetime_original)) {System.out.println ("Shooting time:" +exif.getdescriptio           N (exifdirectory.tag_datetime_original)); } if (Exif.containstag (exifdirectory.tag_aperture)) {System.out.println ("Aperture value:" +exif.getdescription (Exifdire Ctory.           Tag_aperture)); } if (Exif.containstag (exifdirectory.tag_focal_length)) {System.out.println ("focal length:" +exif.getdescription (EXIFD Irectory.           Tag_focal_length)); } if (Exif.containstag (exifdirectory.tag_thumbnail_image_height)) {System.out.println ("Picture size:" +exif.getdescr           Iption (exifdirectory.tag_thumbnail_image_height)); }              }}

Running result: Camera model: NIKON D200 Exposure Time: 1/640 sec shooting time: 2014:05:02 15:00:40 aperture value: F4.5 focal length: 70.0 mm picture size: 1944 pixels

Java get photo-related properties

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.