Java method for reading EXIF information of pictures _java

Source: Internet
Author: User

This article describes the Java method of reading EXIF information of pictures. Share to everyone for your reference. The specific analysis is as follows:

First, what is Exif,exif is the abbreviation for exchangeable image file, which is a format specifically for digital camera photos. This format can be used to record information about the attributes of a digital photograph, such as the camera's brand and model number, the time it takes to shoot, the aperture size, shutter speed, ISO, and so on. In addition, it can record the data taken and the format of the photo so that it can be exported to an EXIF-compatible peripheral, such as a photo printer.

At present, the most common image support EXIF information is JPG, a lot of graphics tools can directly display the image of EXIF information, including now some of the famous photo album site also provides the page used to display photos of EXIF information. This paper mainly introduces how the Java language reads the EXIF information of the image, including how to adjust the image according to the EXIF information to fit the user to browse.

The most easy-to-use Java package for EXIF information processing is the Metadata-extractor written by Drew Noakes, the latest version of which is 2.3.4, which supports the EXIF 2.2 version. You can download the latest version of the project directly from http://www.drewnoakes.com/code/exif/, including its source code.

Note that not every JPG image file contains EXIF information, and you can display it in the attribute-> summary If the picture contains EXIF information when Windows Explorer clicks the selected picture.

Exiftester.java is as follows:

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
 * @author Winter Lau *
/public class Exiftester {public
   static void main ( String[] args) throws Exception {
     file Jpegfile = new file ("C:/1.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);}}


Run Result:

[Exif] Make-olympus optical Co.,ltd [EXIF] model-u10d,s300d,u300d [EXIF] orientation-top, left side (Horizontal/normal) [  Exif] X Resolution-72 dots per inch [exif] Y Resolution-72 dots per inch [EXIF] Resolution Unit-inch [EXIF] Software -22-1012 [EXIF] date/time-2005:04:14 13:47:10 [EXIF] YCbCr positioning-datum Point [EXIF] exposure time
-0.01 sec [EXIF] f-number-f5.2 [EXIF] exposure Program-program creative (slow program) [EXIF] ISO Speed Ratings-80 [Exif] EXIF Version-2.20 [EXIF] date/time original-2005:04:14 13:47:10 [exif] date/time digitized-2005:04:14 13:47:10 [EXIF  ] Components CONFIGURATION-YCBCR [EXIF] exposure Bias Value-0 EV [exif] Max Aperture value-f3.1 [exif] metering Mode -Multi-segment [EXIF] Light Source-unknown [EXIF] Flash-flash did not fire, Auto [EXIF] Focal Length-17.4 mm [exif ] User Comment-[EXIF] FlashPix Version-1.00 [EXIF] Color Space-srgb [EXIF] exif Image Width-1024 pixels [EXIF] Ex If ImageHeight-768 pixels [EXIF] File source-digital still Camera (DSC) [EXIF] Windows XP Title-Landscape [EXIF] Windows XP Author -All the way to the dusty [EXIF] Windows XP Keywords-you are my only [EXIF] Windows XP Subject-my first [EXIF] Custom rendered-normal Process [EXIF ] Exposure Mode-auto exposure [EXIF] white balance-auto white Balance [EXIF] Digital Zoom-Ratio-1 [EXIF] Scene CAPTU Re Type-landscape [EXIF] Gain Control-none [EXIF] contrast-none [EXIF] saturation-none [EXIF] Sharpness-none [Ex
If] Unknown tag (0XC4A5)-80 114 105 110 116 73 77 0 480 2-10 ... [Exif] Compression-jpeg (Old-style) [exif] Thumbnail Offset-2022 bytes [EXIF] Thumbnail Length-5864-bytes [EXIF] Thumbnail

 Data-[5864 bytes of thumbnail data]

Read Only one message:

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 * @author Winter Lau/public class Picexif {public static void main (string[) args) throws E
     xception {File Jpegfile = new file ("C:/1.jpg");
     Metadata Metadata = Jpegmetadatareader.readmetadata (jpegfile);
     Directory exif = Metadata.getdirectory (Exifdirectory.class);
     Iterator tags = exif.gettagiterator (); if (Exif.containstag (Exifdirectory.tag_win_author)) {System.out.println ("Pic AUTHOR is" +exif.getdescription (EXIFDI Rectory.
     Tag_win_author)); } if (Exif.containstag (Exifdirectory.tag_win_title)) {System.out.println ("Pic TITLE is" +exif.getdescription (Exi  
     Fdirectory.tag_win_title)); } if (Exif.containstag (exifdirectory.tag_win_keywords)) {
    SYSTEM.OUT.PRINTLN ("Pic keyword is" +exif.getdescription (exifdirectory.tag_win_keywords)); }
   }
}

I hope this article will help you with your Java programming.

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.