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. ZBT的计算几何模板

    Basic template 一个基础型模板包括一个向量的实现 DATE: 2015-06-01 #define op operator #define __ while #define _0 ret ...

  2. 面向侧面的程序设计AOP-------《一》概述

    Aspect-Oriented Programming(面向方面编程,AOP)正好可以解决这一问题.它允许开发者动态地修改静态的OO模型,构造出一个能够不断增长以满足新增需求的系统,就象现实世界中的对 ...

  3. iOS 一个工程中引用其他工程时编译的Architecture问题

    当引用了其他工程时,在编译时报错,提示你编译指令架构不对,你需要查看一下这几个工程的Architecture部分是否又冲突,比如主工程设置Valid Architecture为armv7 而 另一个子 ...

  4. Java中泛型在集合框架中的应用

    泛型是Java中的一个重要概念,上一篇文章我们说过,当元素存入集合时,集合会将元素转换为Object类型存储,当取出时也是按照Object取出的,所以用get方法取出时,我们会进行强制类型转换,并且通 ...

  5. 【JAVA、C++】LeetCode 001 Two Sum

    Given an array of integers, find two numbers such that they add up to a specific target number. The ...

  6. DP:Cow Bowling(POJ 3176)

    北大教你怎么打保龄球 题目很简单的,我就不翻译了,简单来说就是储存每一行的总数,类似于状态压缩 #include <stdio.h> #include <stdlib.h> # ...

  7. GLSL语言变量

    转自:http://www.th7.cn/Program/cp/201208/87679.shtml   GLSL语言内置的变量,包括内置的顶点属性(attribute).一致变量(uniform). ...

  8. eclipse 优化提速

    1.windows–>perferences–>general–>startup and shutdown关掉没用的启动项: WTP :一个跟myeclipse差不多的东西,主要差别 ...

  9. CSS“反转”为LESS

    LESS(官网在此:http://lesscss.net/)的魅力相信大家都已明了,个人认为它最大的魅力在于能够清晰的展现嵌套关系. 针对现有的项目,它的应用难点主要在于—— 何时转换为css,即是否 ...

  10. C/C++函数参数读取顺序2

    #include <stdio.h>int main(){ int a=1,b=3,c=3; printf("%d, %d, %d",(a++,b++,c++),b,c ...