How to wait for "drawImage" to finish (NOT return)?
Posted on 1997-06-02
It seems necessary, especially in 1.0.2, at times, to wait
for "drawImage" to finish - especially when I am drawing
an image (scaled) into an offscreen image buffer for clean
drawing onto the screen. If the offscreen image isn't
finished being drawn when I draw it to the screen, the
displayed image is blank or maybe incomplete.
However, drawImage returns instantly, even if the draw
operation continues indefinitely. It appears that even if
the source image is ready, the drawImage method may not
complete in one iteration, especialy in the case of
increasing scale. There are nice tools for tracking
loading of an image (MediaTracker, width and height
values..), but there appears to be no equivalent tools for
tracking drawing images to offscreen images, even though
the need can be very similar (the width and height values
appear to be greater than zero once the image is created
and do not seem to be affected by drawing into the image).
Overiding (or implementing) the imageUpdate method of the
ImageObeserver interface seems to provide a possible
solution, but not quite. I have been able to succesfully
wait for the completion of drawImage by unsetting an
"ImageReady" status field and waiting for it to be set by
my imageUpdate method, which has access to the drawImage
status flags. This does seem to work, unless the image
draws in one shot and the imageUpdate method is never
called, which results in a hang.
It seems like waiting for drawImage to finish (NOT just
return) should be a basic requirement with a simple
solution. I haven't found it.
Does anyone have any suggestions?
Thanks for your time,