How do I discover the size of an image file (GIF or JPEG) on disk?

Alex Chaffee

First, load the image. If you have Swing, you can use

    ImageIcon icon = new ImageIcon(args[0]);
    Image image = icon.getImage();
If you do not have Swing, you will need access to a toolkit, a component, and a media tracker. See "How do I make sure an Image is loaded before I try to display it?"

Once you have loaded the image, you can use its getHeight() and getWidth() methods, which work as expected.

0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact