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.

Donations appreciated. Every little $ helps. Or click Google +1.

Related Posts Plugin for WordPress, Blogger...

tags: , ,

  1. 5 Responses to “Java Get Image Width And Height”

  2. Have you come across a quality java image resizer, by the way

    Thanks for the tip

    By Faisal on Jul 17, 2009

  3. nope. so far, this is what i used in resizing my images.

    By tech on Jul 17, 2009

  4. Very interesting post to read on.. I’m really impressed with this article. Looking forward for future posts.

    By how to increase height on Nov 26, 2009

  5. 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.

    By Earleen Ambrosia on Apr 11, 2010

  6. 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;
    }

    By Ali on Mar 8, 2011

Post a Comment