Jaimon's Blog

SimpleImageInfo – A Java class to get image size without loading the whole data


SimpleImageInfo is a Java class to find out an image’s size and mime type without reading the whole image data. It doesn’t have any dependency on AWT or any other libraries. Currently it supports the following image types

  • JPG
  • GIF
  • PNG
  • BMP
  • TIFF

Because it only read the first few bytes, in most cases it only takes less than a millisecond to return the values.

Usage

Getting image data from a byte array

 

SimpleImageInfo imageInfo = new SimpleImageInfo(bytes);
System.out.println("MIME type : " + imageInfo.getMimeType() + " width : " + imageInfo.getWidth() + " height : " + imageInfo.getHeight());

Getting image data from a file

 

SimpleImageInfo imageInfo = new SimpleImageInfo(file);
System.out.println(imageInfo);


Download the source code

Please click here to download the source code.

HTH

Jaimon

Advertisement

January 29, 2011 Posted by | Uncategorized | , , | 21 Comments