Solved

How to wait for "drawImage" to finish (NOT return)?

Posted on 1997-06-02
1
527 Views
Last Modified: 2012-05-04
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,
            Gary Whitten
            whitteng@cs.umass.edu
                  or
            whitteng@con2inc.com
0
Comment
Question by:whitteng
1 Comment
 
LVL 3

Accepted Solution

by:
garik earned 100 total points
ID: 1221138
This should help:
    while (!g.drawImage(img,0,0,this));

To make it easier on VM, run it in a separate thread.
BTW, had no idea that drawImage behaves this way. After reading your question, tried to draw with scaling and got the same problem. Thanks for educational question! :)
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to implement Singleton Design Pattern in Java.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now