Java Get Image Width And Height

The ImageIcon class under javax.swing package tends to be overlooked as it contains nifty methods to get an Image’s dimension. Just pass the path of the image file as parameter when you create a new ImageIcon instance then use either the getIconWidth() or getIconHeight() methods to get the width and height respectively.

ImageIcon ic = new ImageIcon(pathToFile);
System.out.println("width = " + ic.getIconWidth());
System.out.println("height = " + ic.getIconHeight());

Donations appreciated. Every little $ helps. Or click Google +1. Or play the short video on the upper right of this page.

Related Posts Plugin for WordPress, Blogger...