• 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

Graphics Newbie: Image Size

 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wanted to get image size so I could put the height & width attributes into HTML in my Wiki. This seems to get it but it's sure ugly:

In the main thread, getHeight and getWidth always return -1. It looks like I have to wait on another thread to finish loading the image or something before I can get the info I want. Is that right?

(I know synchronized(this) is bad. It will go away soon enough if I get the rest of it right.)
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't have resources around the moment to check but as I remember you can use the MediaTracker class to load your image synchronously. AFAIR it makes this much simpler.

hth, D.
 
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ImageIO.read() will return a BufferedImage which may serve you purposes better.
 
Stan James
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks!!

Hey, I was purposely using createImage() above because the docs warned that getImage() may use a cached copy. I don't see anything about that here. I hope ImageIO isn't using getImage() under the covers!
[ December 30, 2005: Message edited by: Stan James ]
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Stan James:
Thanks!!

Hey, I was purposely using createImage() above because the docs warned that getImage() may use a cached copy. I don't see anything about that here. I hope ImageIO isn't using getImage() under the covers!

[ December 30, 2005: Message edited by: Stan James ]



I believe it uses ImageReader.read() or something similar so I think you're safe.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic