• Post Reply Bookmark Topic Watch Topic
  • New Topic

Graphics Newbie: Image Size

 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • 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.)
 
Don Kiddick
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • 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.
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ImageIO.read() will return a BufferedImage which may serve you purposes better.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!