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.

Related Posts Plugin for WordPress, Blogger...


  1. I don’t agree with everything in this blog post, but you do make some very good points. Im very interested in this subject matter and I myself do alot of research as well. Either way it was a well thoughtout and nice read so I figured I would leave you a comment. Feel free to check out my website sometime and let me know what you think.

  2. I have method like below , and work fine with all image type file , except for .tif , the out put for width and height will return -1 . I couldn’t find the way for it . could you please advise me the way ?

    static int[] imageFileProperlies(File file) throws IOException {
    int[] i = new int[2];
    ImageIcon image = new ImageIcon(file.getAbsolutePath());
    i[0] = image.getIconWidth();
    i[1] = image.getIconHeight();
    return i;

Leave a Reply

Your email address will not be published. Required fields are marked *