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
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());