The example of this article tells the way Java reads the picture EXIF information. Share it for everyone for your reference. The specific analysis is as follows:
First of all, introduce what is exif. Exif is the abbreviation of Exchangeable Image File. This is a format specially set for digital camera photos. This format can be used to record the attribute information of digital photos, such as the brand and model of the camera, the shooting time of the photo, the aperture size, shutter speed, ISO and other information set when shooting. In addition, it can also record shooting data and formatting methods, so that it can output it to peripherals compatible with EXIF format, such as photo printers.
At present, the most common picture format that supports EXIF information is JPG. Many image tools can directly display the EXIF information of the picture. Including some of the currently famous album websites also provide pages to display the EXIF information for showing photos. This article mainly introduces how the Java language reads the EXIF information of the image, including how to adjust the image according to EXIF information to suitable for users to browse.
The easiest and easy-to-use EXIF information processing is the Metadata-Extractor written by Drew Noakes. The latest version of the project is 2.3.4 and supports EXIF 2.2. You can directly from http://www.drewnoakes.com/code/exif/ to download the latest version of the project includes its source code.
It should be noted that not every JPG image file contains EXIF information. You can click the picture in the Windows resource manager. If the picture contains exif information, it will be displayed in the attribute-> Abstract.
Exiftester.java as follows:
Import java.io.file; Import Java.util.itrator; Import com.drew.imaging.jpeg.jpegMetadataReader; Import com.drew.Metadata.directory tadata.metadata; Import com.drew.metadata. Tag; Import Com.drew.metadata.exif.exifdirectory;/*** Test the exif information used to read pictures* @Author Winter Lau*/Public Class ExifTetter {Public Static Void Main (Strin g [] args) Throws Exception { File jpegfile = new file ("C: /1.jpg"); Metadata metadata = jpegmetadataReader.readmetadata (JPEGFILE); Directory exif = ctory.class); ITerator Tags = ExiF.gettaGiterator (); While (tags .hasnext ()) {tag tag = (tag) tags.next (); system.out.println (tag);}}}Run results:
[Exif] Make -Olympus Optical Co., LTD [ExiF] Model -U10D, S300D, U300D [ExiF] Orientation -Top, Left Side (Horizontal / Normal) [exif] TS 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 POSITING -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 Version [ExiF] Date] 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 ENT- [ExiF] Flashpix Version -1.00 [Exif] Color Space -SRGB [ExiF] ExiF Image Width -1024 Pixels [ExiF] ExiF Image Height -768 Pixels [ExiF] File Source -DIGITAL Stillra (DSC) [ExiF] w Indows XP Title -Scenery [ExiF] Windows XP Author -One Wind Dust [EXIF] Windows XP Keywords -You are my only [ExiF] Windows XP Subject -My First [ExiF] CUSTORED -NORMAL Process [ExiF] Exposure Mode -Auto Expo Sure [exif] White Balance- Auto White Balance [ExiF] Digital Zoom Ratio -1 [ExiF] Scene Capture Type -LANDSCAPE [ExiF] Gain Control -None [ExiF] Contrast -None [ExiF] Saturation ] Sharpness -NONE [ExiF] 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 [Exifs [Exifs [Exifs ] Thumbnail Data - [5864 bytes of thumbnail data]
Read only a certain information:
package test; Import Java.io.File; Import Java.util.itrator; Import com.drew.imaging.jpegMetadataRader; Import com.drew.metadata.directory; port com.drew.metadata.metadata; Import com.drew .metadata.tag; Import Com.drew.metadata.exif.exifdirectory;/*** Test the ExiF information used to read pictures* @AutHor Winter Lau*/Public Class PICEXIF {Public Static main (string [] args) Throws Exception {File JPEGFILE = New File ("C: /1.jpg"); metadata metadata = JPEGMETADADADER.READMETADADATA (JPEGFILE); Directory Exif = tdirectory (exifdirectory.class); Iterator tags = exif.gettagiterator (); If (exif.containstag (exifdirectory.tag_win_author) {system.out.println ("pic author is"+exif.getDescription (exifdirectory.tag_win_AutHor), } if (exif.containstag (exifdirectory.tag_win_title)) {System.out .println ("Pic Title is"+ExiF.GetDescript (exifdirectory.tag_win_title));} if (exif.containstag (exifdirectory.tag_Keywords) T.println ("PIC Keyword is"+ExiF.getDescript (exifdirectory. Tag_win_keywords));}}}It is hoped that this article is helpful to everyone's Java program design.