image - how to read JPEG file attributes with Java? -


i want read information image (jpg) has information included digital camera creation date, focus, flash on off, ... how can information.

my first idea was.

bufferedimage image = imageio.read(filepicture); if (image().getpropertynames() != null) { (int j = 0; j < image().getpropertynames().length; j++) { string key = image().getpropertynames()[j]; string value = (string) image().getproperty(key); system.out.println(key + ": " + value); } } 

but getpropertynames() returns null!

another simple option use metadata-extractor:

metadata metadata = imagemetadatareader.readmetadata(imagepath); 

to iterate values in file:

for (directory directory : metadata.getdirectories()) {     (tag tag : directory.gettags()) {         system.out.println(tag);     } } 

you can read specific values specific directories:

// obtain exif subifd directory exifsubifddirectory directory      = metadata.getfirstdirectoryoftype(exifsubifddirectory.class);  // query datetime tag's value date date = directory.getdate(exifsubifddirectory.tag_datetime_original); 

the library available maven users too.

(full disclosure: author of library)


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -