• Post Reply Bookmark Topic Watch Topic
  • New Topic

Any coding examples to use ImageObserver  RSS feed

 
Greenhorn
Posts: 23
1
  • Mark post as helpful
  • send pies
  • 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: 779
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!