Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 1997-06-02
1
Medium Priority
?
567 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 200 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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 learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

604 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