Get the image file(s) some informations,Including the Make,Model,Date/Time,etc
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的更多相关文章
- Python File I/O
File is a named location on disk to store related information. It is used to permanently store data ...
- ORA-19602: cannot backup or copy active file in NOARCHIVELOG mode
备份数据库,报错如下 RMAN> backup database; Starting backup at -JAN- allocated channel: ORA_DISK_1 channel ...
- 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 ...
- Extension of write anywhere file system layout
A file system layout apportions an underlying physical volume into one or more virtual volumes (vvol ...
- Java API —— File类
1.File类的概述 文件和目录路径名的抽象表示形式,创建File对象后,仅仅是一个路径的表示,不代码具体的事物一定是存在的. 2.构造方法 · public File ...
- Android(java)学习笔记87:File类使用
package cn.itcast_01; import java.io.File; /* * 我们要想实现IO的操作,就必须知道硬盘上文件的表现形式. * 而Java就提供了一个类File供我们使用 ...
- input[type='file']样式美化及实现图片预览
前言 上传图片是常见的需求,多使用input标签.本文主要介绍 input标签的样式美化 和 实现图片预览. 用到的知识点有: 1.input标签的使用 2.filelist对象 和 file对象 3 ...
- 生成缓存文件cache file
生成缓存文件cache file class Test{ public function index(){ $arrConfig = Array( 'name' => 'daicr', 'age ...
- js 图片base64转file文件的两种方式
js 图片base64转file文件的两种方式 https://blog.csdn.net/yin13037173186/article/details/83302628 //将base64转换为bl ...
随机推荐
- FOJ 1205
Problem 1205 小鼠迷宫问题 Accept: 522 Submit: 1679 Time Limit: 1000 mSec Memory Limit : 32768 KB Pro ...
- NGINX userid 分析、解码
NGINX userid 分析.解码 生成userid的代码在 http/modules/ngx_http_userid_filter_module.c 大概550行左右. uid_set 是4个ui ...
- x:Name标记特性与Name属性
本文转载自silvergingko的专栏 在Xaml中定义了一个元素后,如果后面要使用该元素,则必须为该元素定义一个元素名称,在随后的Xaml中,通过元素名称来使用该元素. 在Xaml中,元素的名称定 ...
- 11.python之线程,协程,进程,
一,进程与线程 1.什么是线程 线程是操作系统能够进行运算调度的最小单位.它被包含在进程之中,是进程中的实际运作单位.一条线程指的是进程中一个单一顺序的控制流,一个进程中可以并发多个线程,每条线程并行 ...
- tomcat下不用项目名直接访问项目
把tomcat下的项目名称改为ROOT,访问项目的时候,不用输入项目名称,输入地址,如192.168.182.100:8080即可.
- UTF8-GBK WideCharToMultiByte MultiByteToWideChar
//MFC版本 CString UTF8ToGBK(const CString& strUTF8){ //确定转换为Unicode需要多少缓冲区(返回值也包含了最后一个NULL字符) int ...
- struts1老古董配置
<!--Struts1 struts-config.xml Demo --><?xml version="1.0" encoding="UTF-8&qu ...
- ip
D组播地址 主机号 用于识别该网络中的主机. IP地址分为五类,A类保留给政府机构,B类分配给中等规模的公司,C类分配给任何需要的人,D类用于组播,E类用于实验,各类可容纳的地址数目不同. A.B.C ...
- HTML CSS 中DIV内容居中汇总
转载博客(http://www.cnblogs.com/dearxinli/p/3865099.html) (备注:DIV居中情况,网上谈到也比较多,但是这篇文字,相对还是挺全面,现转载,如果冒犯,还 ...
- C#学习笔记——Show()与ShowDialog()的区别
用Show()调用的窗体不会返回任何值,在使用form.Show()显示form以后,会马上继续执行form.Show()后面的语句.而用ShowDialog()调用的窗体会返回一个DialogRes ...