?
Solved

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

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month13 days, 6 hours left to enroll

801 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