首页 > 代码库 > java获取照片相关属性
java获取照片相关属性
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; /** * 测试用于读取图片的EXIF信息 */public class ExifTester { public static void main(String[] args) throws Exception { File jpegFile = new File("E:\\图片\\2.JPG"); Metadata metadata = http://www.mamicode.com/JpegMetadataReader.readMetadata(jpegFile);>
需要jar包:metadata-extractor-2.3.0
运行结果[Exif] Thumbnail Image Width - 2896 pixels[Exif] Thumbnail Image Height - 1944 pixels[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 - 300 dots per inch[Exif] Y Resolution - 300 dots 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/640 sec[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/639 sec[Exif] Aperture Value - F4.5[Exif] Exposure Bias Value - 2/3 EV[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.0 mm[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 - 1944 pixels[Exif] Exif Image Height - 1944 pixels[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 Length 35 - 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
获取需要的数据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; /** * 测试用于读取图片的EXIF信息 * @author Winter Lau */public class PicExif { public static void main(String[] args) throws Exception { File jpegFile = new File( "E:\\图片\\2.JPG"); Metadata metadata = http://www.mamicode.com/JpegMetadataReader.readMetadata(jpegFile);"相机型号:"+exif.getDescription(ExifDirectory.TAG_MODEL)); } if(exif.containsTag(ExifDirectory.TAG_EXPOSURE_TIME)){ System.out.println("曝光时间:"+exif.getDescription(ExifDirectory.TAG_EXPOSURE_TIME)); } if(exif.containsTag(ExifDirectory.TAG_DATETIME_ORIGINAL)){ System.out.println("拍摄时间:"+exif.getDescription(ExifDirectory.TAG_DATETIME_ORIGINAL)); } if(exif.containsTag(ExifDirectory.TAG_APERTURE)){ System.out.println("光圈值:"+exif.getDescription(ExifDirectory.TAG_APERTURE)); } if(exif.containsTag(ExifDirectory.TAG_FOCAL_LENGTH)){ System.out.println("焦距:"+exif.getDescription(ExifDirectory.TAG_FOCAL_LENGTH)); } if(exif.containsTag(ExifDirectory.TAG_THUMBNAIL_IMAGE_HEIGHT)){ System.out.println("图片尺寸:"+exif.getDescription(ExifDirectory.TAG_THUMBNAIL_IMAGE_HEIGHT)); } }}
运行结果:相机型号:NIKON D200曝光时间:1/640 sec拍摄时间:2014:05:02 15:00:40光圈值:F4.5焦距:70.0 mm图片尺寸:1944 pixels
java获取照片相关属性
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。