• 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

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

 
Ranch Hand
Posts: 146
1
IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 146
1
IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic