Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Get image size  RSS feed

 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • 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).
 
John McDonald
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!