Java Get Image Width And Height
Posted by admin on
September 15, 2008
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());










