Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

What's the purpose of ImageObserver parameter in Graphics2D.drawImage  RSS feed

 
Quazi Irfan
Ranch Hand
Posts: 104
1
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand the purpose of ImageObserver parameter in drawImage method from Graphics2d class.

Here is the method signature,

On oracle tutorial it says, "the observer parameter notifies the application of updates to an image that is loaded asynchronously. The observer parameter is not frequently used directly and is not needed for the BufferedImage class, so it usually is null."

On the java doc it says, "'observer' object to be notified as more of the image is converted."

But neither of the two explanation is clear to me. What is the use of ImageObserver?
 
Paul Clapham
Sheriff
Posts: 22493
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It dates back to the earliest days of Java, when you might be using that code in an applet which was downloading an image over a very slow connection. So instead of pausing the application to wait for the image to be totally downloaded, you would start displaying the part of the image which you had already. Then you'd do something with the ImageObserver object so that as more of the image arrived over the dial-up line you would display the new part, until the whole image was displayed.

As the tutorial suggests, it's unlikely you would need to use it today. For one thing you probably wouldn't be writing an applet, so the image is most likely on the same machine as the application. No network latency then. And even if you were writing an applet, you probably wouldn't be worrying about network latency either.
 
Quazi Irfan
Ranch Hand
Posts: 104
1
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Very clear answer. Thank you.

Yes, I am making a desktop 2d platformer so all the resource files would be available locally. I am using Java2d because I want to teach myself about the architecture first(update and render loop, handling different threads, application performance monitoring) before employing complicated graphics pipeline(opengl wrappers like lwjgl or jogl).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!