Solved

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

Posted on 1997-06-02
1
552 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
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:

729 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