• 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

image width and height

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am using this statement in jsp page to get image and it's width and height -

Image im = Toolkit.getDefaultToolkit().getImage("E:/photos/thumb/first.jpg");


width = im.getWidth(null);
height = im.getHeight(null);


here problem is that , first time it returns -1 to width and height and after refershing page it returns actual width and height of image.


I think this problem is related to awt and image classes so i posted to it in awt section rather than jsp section.

just tell me how can i get actual width and height in first time.
 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like the image hasn't completely loaded the first time you call getWidth and getHeight.

Use a MediaTracker to obtain the image instead.

Cheers,
James
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
width/height works OK if you can create your image like this

Image im = new ImageIcon("Test.gif").getImage();
 
reply
    Bookmark Topic Watch Topic
  • New Topic