Read Image Metadata from single file with Java -
i want read image metadata single file. tried following code:
http://johnbokma.com/java/obtaining-image-metadata.html
when run it, build successful
nothing happens.
public class metadata { public static void main(string[] args) { metadata meta = new metadata(); int length = args.length; ( int = 0; < length; i++ ) meta.readanddisplaymetadata( args[i] ); } void readanddisplaymetadata( string filename ) { try { file file = new file( filename ); imageinputstream iis = imageio.createimageinputstream(file); iterator<imagereader> readers = imageio.getimagereaders(iis); if (readers.hasnext()) { // pick first available imagereader imagereader reader = readers.next(); // attach source reader reader.setinput(iis, true); // read metadata of first image iiometadata metadata = reader.getimagemetadata(0); string[] names = metadata.getmetadataformatnames(); int length = names.length; (int = 0; < length; i++) { system.out.println( "format name: " + names[ ] ); displaymetadata(metadata.getastree(names[i])); } } } catch (exception e) { e.printstacktrace(); } } }
please :)
you haven't specified path file correctly. change below should indicate this!
public static void main(string[] args) { metadata meta = new metadata(); int length = args.length; ( int = 0; < length; i++ ) { if (new file(args[i]).exists()) { meta.readanddisplaymetadata( args[i] ); } else { system.out.println("cannot find file: " + args[i]); } } }
edit - simpler code example
we statically defining file use.
public static void main(string[] args) { metadata meta = new metadata(); string filename = "c:\\users\\luckheart\\pictures\\sample pictures\\koala.jpg"; if (new file(filename).exists()) { meta.readanddisplaymetadata(filename); } else { system.out.println("cannot find file: " + filename); } }
Comments
Post a Comment