• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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