This is a blog about how to get the image file(s) some informations.Including the Make,Model,Date/Tiime,etc.

while,how can do it? I should use a tool which name is :Exif,writed by Java,and now its version is 2.6.4.

and you can get more from the here. or osChina

How does it work?

while,I hava a demo and I will show the complete code to you.

 /**
*
*/
package com.b510.test; import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map; import com.drew.imaging.jpeg.JpegMetadataReader;
import com.drew.imaging.jpeg.JpegProcessingException;
import com.drew.metadata.Directory;
import com.drew.metadata.Metadata;
import com.drew.metadata.Tag;
import com.drew.metadata.exif.ExifIFD0Directory;
/**
* only handle the "jpeg" format image file(s)<br>
* <a href="https://drewnoakes.com/code/exif/">Get more about the Exif>></a>
* @author Hongten
* @date 2013-12-20
*/
public class ExifTester { //separating character
public static final String LINE = "-";
public static final String RIGHT_PARENTHESES = "]"; public static void main(String[] args) throws Exception {
//if you want to run this code.you should be rewrite the following array of String.
//and be sure the correct path of the image file
String[] pathNames = {
"C:/2013-02-08_12-24-54_100.jpg",//motorola ME865
"C:/20022013011.jpg",//nokia 6700s
"C:/IMG_0018.JPG",//download from web site
"C:/IMG_0697.JPG", //ipad4
"C:/P1080402.JPG"//Panasonic DMC-LX5
};
List<File> files = new ArrayList<File>();
for (String pathname : pathNames) {
File file = new File(pathname);
files.add(file);
}
List<Map<String, String>> imagesInfo = getImageInfoOfExif(files);
printImagesInfo(imagesInfo);
//Get the image file informations
File file = new File("C:/IMG_0697.JPG");
Map<String, String> map = getImageInfoOfExif(file);
System.out.println("##### the image file informations");
HandleMap(map);
} /**
* print the abstracts of image file
* @param imagesInfo
*/
private static void printImagesInfo(List<Map<String, String>> imagesInfo) {
if(!imagesInfo.isEmpty()){
for(Map<String, String> map: imagesInfo){
HandleMap(map);
System.out.println("======================================");
}
}
} /**
* @param map
*/
private static void HandleMap(Map<String, String> map) {
Iterator<String> iterator = map.keySet().iterator();
while (iterator.hasNext()) {
String name = iterator.next();
String value = map.get(name);
printInfo(name, value);
}
} /**
* @param name
* @param value
*/
private static void printInfo(String name, String value) {
System.out.println(name + " : " + value);
} /**
* get the abstracts of the image file
* @param jpegFile
* @return
* @throws JpegProcessingException
* @throws IOException
*/
@SuppressWarnings("unchecked")
private static Map<String, String> getImageInfoOfExif(File jpegFile) throws JpegProcessingException, IOException {
Metadata metadata = JpegMetadataReader.readMetadata(jpegFile);
Directory exifDirectory = metadata.getDirectory(ExifIFD0Directory.class);
Collection tags = exifDirectory.getTags();
Iterator iterator = tags.iterator();
Map<String, String> abstractsMap = new HashMap<String, String>();
while (iterator.hasNext()) {
Tag tag = (Tag) iterator.next();
String[] tagArrays = tag.toString().split(LINE);
String[] abstracts = tagArrays[0].trim().split(RIGHT_PARENTHESES);
abstractsMap.put(abstracts[1].trim(), tagArrays[1].trim());
}
return abstractsMap;
} /**
* handle more than one image files
* @param files
* @return
* @throws JpegProcessingException
* @throws IOException
*/
private static List<Map<String, String>> getImageInfoOfExif(List<File> files) throws JpegProcessingException, IOException{
if(files == null)return null;
List<Map<String, String>> list = new ArrayList<Map<String,String>>();
if(files.size() > 0){
for(File file: files){
Map<String, String> map = getImageInfoOfExif(file);
list.add(map);
}
}
return list;
}
}

and the output as following:

Date/Time : 2013:02:08 12:24:53
Model : ME865
X Resolution : 72 dots per inch
YCbCr Positioning : Center of pixel array
Resolution Unit : Inch
Y Resolution : 72 dots per inch
Make : Motorola
======================================
Orientation : Top, left side (Horizontal / normal)
Model : 6700s
X Resolution : 300 dots per inch
YCbCr Positioning : Center of pixel array
Resolution Unit : Inch
Y Resolution : 300 dots per inch
Make : Nokia
======================================
Orientation : Top, left side (Horizontal / normal)
X Resolution : 72 dots per inch
YCbCr Positioning : Center of pixel array
Resolution Unit : Inch
Y Resolution : 72 dots per inch
======================================
Software : 6.1.3
Date/Time : 2013:06:27 23:31:19
Orientation : Right side, top (Rotate 90 CW)
Model : iPad
X Resolution : 72 dots per inch
YCbCr Positioning : Center of pixel array
Resolution Unit : Inch
Y Resolution : 72 dots per inch
Make : Apple
======================================
Software : Ver.1.0
Unknown tag (0xc4a5) : [208 bytes]
Model : DMC
Orientation : Top, left side (Horizontal / normal)
YCbCr Positioning : Datum point
Unknown tag (0xc6d3) : [128 bytes]
Date/Time : 2013:01:04 00:01:06
X Resolution : 180 dots per inch
Unknown tag (0xc6d2) : [64 bytes]
Resolution Unit : Inch
Artist :
Y Resolution : 180 dots per inch
Make : Panasonic
======================================
##### the image file informations
Software : 6.1.3
Date/Time : 2013:06:27 23:31:19
Orientation : Right side, top (Rotate 90 CW)
Model : iPad
X Resolution : 72 dots per inch
YCbCr Positioning : Center of pixel array
Resolution Unit : Inch
Y Resolution : 72 dots per inch
Make : Apple

it work and the output is so cool.

then, you should have a try!

Get the image file(s) some informations,Including the Make,Model,Date/Time,etc的更多相关文章

  1. Python File I/O

    File is a named location on disk to store related information. It is used to permanently store data ...

  2. ORA-19602: cannot backup or copy active file in NOARCHIVELOG mode

    备份数据库,报错如下 RMAN> backup database; Starting backup at -JAN- allocated channel: ORA_DISK_1 channel ...

  3. Display file information in the document window

    [Display file information in the document window] The status bar is located at the bottom of every d ...

  4. Extension of write anywhere file system layout

    A file system layout apportions an underlying physical volume into one or more virtual volumes (vvol ...

  5. Java API —— File类

    1.File类的概述         文件和目录路径名的抽象表示形式,创建File对象后,仅仅是一个路径的表示,不代码具体的事物一定是存在的. 2.构造方法         · public File ...

  6. Android(java)学习笔记87:File类使用

    package cn.itcast_01; import java.io.File; /* * 我们要想实现IO的操作,就必须知道硬盘上文件的表现形式. * 而Java就提供了一个类File供我们使用 ...

  7. input[type='file']样式美化及实现图片预览

    前言 上传图片是常见的需求,多使用input标签.本文主要介绍 input标签的样式美化 和 实现图片预览. 用到的知识点有: 1.input标签的使用 2.filelist对象 和 file对象 3 ...

  8. 生成缓存文件cache file

    生成缓存文件cache file class Test{ public function index(){ $arrConfig = Array( 'name' => 'daicr', 'age ...

  9. js 图片base64转file文件的两种方式

    js 图片base64转file文件的两种方式 https://blog.csdn.net/yin13037173186/article/details/83302628 //将base64转换为bl ...

随机推荐

  1. python安装问题

    安装MinGW之后 出现.. 解决方案 ================

  2. ASP.NET MVC 入门系列教程

    ASP.NET MVC 入门系列教程 博客园ASP.NET MVC 技术专题 http://kb.cnblogs.com/zt/mvc/ 一个居于ASP.NET MVC Beta的系列入门文章,有朋友 ...

  3. In-App Purchases验证

    package com.demo.controller.web.app; import java.io.BufferedOutputStream; import java.io.BufferedRea ...

  4. 23.跳台阶问题[Fib]

    [题目] 一个台阶总共有n级,如果一次可以跳1级,也可以跳2级.求总共有多少总跳法,并分析算法的时间复杂度. [分析] 首先我们考虑最简单的情况.如果只有1级台阶,那显然只有一种跳法.如果有2级台阶, ...

  5. PHP 转换接口编码

    2014年10月20日 10:45:19 有些时候调用接口的时候返回数据的编码不是utf-8的,需要转码 foreach ($arrInfo as $k => $v) { $encodeing ...

  6. mysql varchar

    2013年9月13日 14:58:43 MYSQL的varchar数据类型 先说结论: 如果设置字段长度为30,字符编码为utf8,那么一个汉字算一个字符,一个数字算一个字符,一个字母也算一个字符 版 ...

  7. MPlayer-ww 增加边看边剪切功能+生成高质量GIF功能

    http://pan.baidu.com/s/1eQm5a74 下载FFmpeg palettegen paletteuse documentation 需要下载 FFmpeg2.6 以上 并FFmp ...

  8. Java for LeetCode 141 Linked List Cycle

    Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using ex ...

  9. 【python】pathlib库

    pathlib在python3.2以上开始默认支持,在python2.7中如果要使用需要安装 pip install pathlib pathlib更多参考资料:http://pathlib.read ...

  10. Myeclipse中全部文件设置成UTF-8

    如果要使插件开发应用能有更好的国际化支持,能够最大程度的支持中文输出,则最好使 Java文件使用UTF-8编码.然而,Eclipse工作空间(workspace)的缺省字符编码是操作系统缺省的编码,简 ...