ImageInfo.java | Class | Get file format, image resolution, number of bits per pixel and optionally
number of images, comments and physical resolution from
JPEG, GIF, BMP, PCX, PNG, IFF, RAS, PBM, PGM, PPM and PSD files
(or input streams).
Use the class like this:
ImageInfo ii = new ImageInfo();
ii.setInput(in); // in can be InputStream or RandomAccessFile
ii.setDetermineImageNumber(true); // default is false
ii.setCollectComments(true); // default is false
if (!ii.check()) {
System.err.println("Not a supported image file format.");
return;
}
System.out.println(ii.getFormatName() + ", " + ii.getMimeType() +
", " + ii.getWidth() + " x " + ii.getHeight() + " pixels, " +
ii.getBitsPerPixel() + " bits per pixel, " + ii.getNumberOfImages() +
" image(s), " + ii.getNumberOfComments() + " comment(s).");
// there are other properties, check out the API documentation
You can also use this class as a command line program.
Call it with a number of image file names and URLs as parameters:
java ImageInfo *.jpg *.png *.gif http://somesite.tld/image.jpg
or call it without parameters and pipe data to it:
java ImageInfo < image.jpg
Known limitations:
- When the determination of the number of images is turned off, GIF bits
per pixel are only read from the global header.
For some GIFs, local palettes change this to a typically larger
value.
|