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 ...
随机推荐
- HDOJ 1026 dfs路径保存
#include<cstdio> #include<cstring> #include<cmath> ][]; #define inf 0xffffff int n ...
- 【转】INSTALL_FAILED_NO_MATCHING_ABIS 的解决办法
在Android模拟器上安装apk的时候出现 INSTALL_FAILED_NO_MATCHING_ABIS 这个错误提示的解决办法. 是由于使用了native libraries .该nativ ...
- Balanced Binary Tree
Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary ...
- php中GD库的简单使用
在php中需要图像处理的地方GD库会发挥重要的作用,php可以创建并处理包括GIF,PNG,JPEG,WBMP以及XPM在内的多种图像格式,简单的举几个例子: 1.用GD库会创建一块空白图片,然后绘制 ...
- 【JAVA、C++】LeetCode 013 Roman to Integer
Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 t ...
- 防止黑客对服务器IP地址的攻击
下面的参数都是系统默认的: [root@ok etc]# cat /proc/sys/net/ipv4/conf/eth0/accept_source_route [root@ok etc]# cat ...
- SQLServer2008 和SQLServer2008 R2版本导出 数据库结构和数据sql
①SQLServer2008 版本导出 数据库结构和数据sql ②SQLServer2008R2 版本导出 数据库结构和数据sql 采集 #HUABAN_WIDGETS .HUABAN-red-nor ...
- Android APK反编译详解(附图)(转)
这段时间在学Android应用开发,在想既然是用Java开发的应该很好反编译从而得到源代码吧,google了一下,确实很简单,以下是我的实践过程. 在此郑重声明,贴出来的目的不是为了去破解人家的软件, ...
- c++工程vs导入工程时发生LNK1207
I have installed VS 2012 , but i have VS 2010 also. After I open VS 2010 projects with VS 2012 and ...
- sql经典习题及其答案(纠正错误版)
--网上有好多这套题的答案,但是经过我的验证,有很多都是错的,误人子弟--这是我自己纠正以后的版本 然后呢如果我写的还有不对的欢迎批评指正!--(1)查询2006年以后(包括2006年)的投稿情况,列 ...