• 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

Any coding examples to use ImageObserver

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

I was using the code "image = Toolkit.getDefaultToolkit().getImage(url)" to get the picture image.
But subsequent statemetns imagewidth = image.getWidth() returns -1.
As per the Javadoc: If the width is not yet known, this method returns -1 and the specified ImageObserver object is notified later.
I know that image = ImageIO.read(url) will fully load the image and get the correct width and height in image.getwidth()

As ImageObserver can track the status of image loading, but I am not sure how to code ImageObserver to do the tracking.

Is there some coding examples on this that I can learn from ?

Thanks.
 
Rancher
Posts: 1093
29
Netbeans IDE Oracle MySQL Database Tomcat Server C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Simple, don't do it that way. The ToolKit method you have shown has been not recommend for almost a couple decades.

Use ImageIO instead.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic