• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Get image size

 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using the Toolkit class to load images often requires a MediaTracker to block program execution until the image is fully–loaded. You can query the image for its width and height (see Image api) once it is fully–loaded. Until then the methods return a value of -1. For the size you can use file.length if you can get a reference to a local (hard drive) file or for loading over the network you can use the URLConnection method getContentLength.

If you are using j2se 1.4+ you can use the ImageIO class for loading. The read methods return a BufferedImage which has its own methods for getting width and height (see BufferedImage api).
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,
I am using tool kit to load an image but I don't know to get the size, height and width of the image. Is there anyway to get these properties of the image? Thanks.

John
reply
    Bookmark Topic Watch Topic
  • New Topic