Get the image file(s) some informations,Including the Make,

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.

* com.b510.test; java.io.File; 7 import java.io.IOException; 8 import java.util.ArrayList; 9 import java.util.Collection; 10 import java.util.HashMap; 11 import java.util.Iterator; 12 import java.util.List; 13 import java.util.Map; com.drew.imaging.jpeg.JpegMetadataReader; 16 import com.drew.imaging.jpeg.JpegProcessingException; 17 import com.drew.metadata.Directory; 18 import com.drew.metadata.Metadata; 19 import com.drew.metadata.Tag; 20 import com.drew.metadata.exif.ExifIFD0Directory; * only handle the “jpeg” format image file(s)<br>”>Get more about the Exif>></a> Hongten 25 * @date 2013-12-20 ExifTester {String LINE = “-“;String RIGHT_PARENTHESES = “]”;main(String[] args) throws Exception { 35//if you want to run this code.you should be rewrite the following array of String.String[] pathNames = { “C:/20022013011.jpg”,”C:/IMG_0018.JPG”,”C:/IMG_0697.JPG”, “C:/P1080402.JPG”}; 44List<File> files = new ArrayList<File>(); 45for (String pathname : pathNames) { 46File file = new File(pathname); 47 files.add(file); 48 } 49List<Map<String, String>> imagesInfo = getImageInfoOfExif(files); 50 printImagesInfo(imagesInfo);File file = new File(“C:/IMG_0697.JPG”); 53Map<String, String> map = getImageInfoOfExif(file); 54System.out.println(“##### the image file informations”); 55 HandleMap(map); 56 }* print the abstracts of image file imagesInfoprintImagesInfo(List<Map<String, String>> imagesInfo) { 63if(!imagesInfo.isEmpty()){ 64for(Map<String, String> map: imagesInfo){ 65 HandleMap(map); 66System.out.println(“======================================”); 67 } 68 } 69 } mapHandleMap(Map<String, String> map) { 75Iterator<String> iterator = map.keySet().iterator(); 76while (iterator.hasNext()) { 77String name = iterator.next(); 78String value = map.get(name); 79 printInfo(name, value); 80 } 81 } name value printInfo(String name, String value) { 88System.out.println(name + ” : ” + value); 89 }* get the abstracts of the image file jpegFile JpegProcessingException IOException@SuppressWarnings(“unchecked”)Map<String, String> getImageInfoOfExif(File jpegFile) throws JpegProcessingException, IOException {100Metadata metadata = JpegMetadataReader.readMetadata(jpegFile);101Directory exifDirectory = metadata.getDirectory(ExifIFD0Directory.class);102Collection tags = exifDirectory.getTags();103Iterator iterator = tags.iterator();104Map<String, String> abstractsMap = new HashMap<String, String>();105while (iterator.hasNext()) {106Tag tag = (Tag) iterator.next();107String[] tagArrays = tag.toString().split(LINE);108String[] abstracts = tagArrays[0].trim().split(RIGHT_PARENTHESES);109abstractsMap.put(abstracts[1].trim(), tagArrays[1].trim());110 }111return abstractsMap;112 }* handle more than one image files files JpegProcessingException IOExceptionList<Map<String, String>> getImageInfoOfExif(List<File> files) throws JpegProcessingException, IOException{;123List<Map<String, String>> list = new ArrayList<Map<String,String>>();124if(files.size() > 0){125for(File file: files){126Map<String, String> map = getImageInfoOfExif(file);127 list.add(map);128 }129 }130return list;131 }132 },不付出,却一定不会有收获,不要奢望出现奇迹。

Get the image file(s) some informations,Including the Make,

相关文章:

你感兴趣的文章:

标签云: