How should Java's drawImage() be used? I do not find the JDK documentation very forthcoming. For example all drawImage signatures require an ImageObserver but the documentation for this is not very helpful for new users.
You can get away with Graphics.drawImage(img, x, y, null)
[or similar]. The ImageObserver
parameter is a callback to inform you of the progress of the draw operation; and is really only useful if you're fetching the Image parameter asynchronously.
To be clearer, if you call drawImage
with an incompletely loaded Image it will:
Image
as possible (all that is loaded)ImageObserver
when more of the Image is availableBasically, if you're working with in memory Image
s (either loaded from the file system, or constructed by your program) don't worry about the ImageObserver
parameter. If you're loading Image
s across the network and not explicitly waiting for them to load, you'll need to employ an ImageObserver
to make sure "completely" draw an Image
.