Feb 13, 2012

Simple way of finding Image height and width

Ok here is a simple way to find the length and width of an image in java dynamically , just in case if you have stored your image in the db in the form of byte array. In our application we had an option of uploading images where we saved only the image size but not the dimensions. I found this way more easy for getting image height and width.

All you have to do is import the "ImageIcon" package from javax.swing package and simply add the byte array from the db and pass it as a parameter.

 ImageIcon imageIcon = new ImageIcon(img.getYourImageByteArray());
int width = imageIcon.getIconWidth();
int height = imageIcon.getIconHeight();
 System.out.println("Image Height : "+height +"  Image Width : "+width);

This worked for me , Cheers !

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home