JDK-4618975 : Graphics.drawImage() does not notify ImageObserver
  • Type: Bug
  • Component: docs
  • Sub-Component: guides
  • Affected Version: 1.4.0,5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic,solaris_7
  • CPU: generic,sparc
  • Submitted: 2002-01-03
  • Updated: 2017-05-16
  • Resolved: 2003-10-27
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availabitlity Release.

To download the current JDK release, click here.
5.0 b26Fixed
Name: atR10191			Date: 01/03/2002

specifications for methods
public abstract boolean drawImage(Image img, ... ,ImageObserver observer)
of class Graphics states
If the image has not yet been completely loaded, then drawImage returns false.
As more of the image becomes available, the process that draws the image
notifies the specified image observer".
The example below shows that after first call of drawImage(), following
calls of the method do not cause observer to be notified, when Image
is animated image.
============ Test56.java ==============================================
import java.awt.*;
import java.awt.image.*;

public class Test56 {
    public static void main(String argv[]) {
        Test56 test = new Test56();
    void testRun(){
        Frame frm = new Frame();
        frm.setSize(300, 300);
        Graphics g = frm.getGraphics();

        int w = 50;
        int h = 50;
        int size = w * h;
        int[] pix = new int[size];

        int value = frm.getBackground().getRGB();
        for (int i = 0; i <size; i++) {
            pix[i] = value;

        MemoryImageSource src = new MemoryImageSource(w, h, pix, 0, w);

        Image img = frm.createImage(src);
        MediaTracker tracker = new MediaTracker(frm);

        tracker.addImage(img, 0);
        MyImageObserver observer = new MyImageObserver();

        g.drawImage(img, 0, 0, new Container());

        if (!g.drawImage(img, 1, 1, observer)) {
            try {
            } catch (InterruptedException e) {
                 System.out.println("unable to load image");
            if (!observer.bImageUpdateWasCalled) {
                 System.out.println("ImageObserver was not notified " +
                     "by time when image was completely loaded");

class MyImageObserver extends Container {
    boolean bImageUpdateWasCalled = false;

    public boolean imageUpdate(Image img, int infoflags, int x,
                               int y, int width, int height) {
        bImageUpdateWasCalled = true;
        return super.imageUpdate(img, infoflags, x, y, width, height);
======== end of Test56.java ==========================================
======== output of Test56 ==========================================
ImageObserver was not notified by time when image was completely loaded
======== end of output of Test56 ==========================================
                      <TD colspan="2" bgcolor="#BFBFBF"> </td>

<a name="comments"></a>
                    <!-- COMMENTS -->
                      <TD bgcolor="#BFBFBF" align="left" valign="bottom" height="24"> 
		        <img src="https://central.sun.net/https%3A//swbtres.central.sun.com%3A443/bugz/images/dot.gif" width="10">Comments
                      <TD bgcolor="#BFBFBF" align="left" valign="bottom" height="24"> 
			<!-- BEGIN:TBR Mohan
 			<A href="javascript:doDateStampSubmit(document.editbug_general, 'comments');"><font size="-1">[ Date Stamp ]</font></A> 
			<img src="https://central.sun.net/https%3A//swbtres.central.sun.com%3A443/bugz/images/dot.gif" width="18">
			END:TBR -->
			<A href="javascript:doFullPageSubmit(document.editbug_general, 'comments');"><font size="-1">[ Full Page ]</font></a>
		        <img src="https://central.sun.net/https%3A//swbtres.central.sun.com%3A443/bugz/images/dot.gif" width="22">
		        <FONT size="-1" color="darkblue">---  Enter SUN Proprietary data here  ---</font>

                      <TD bgcolor="#BFBFBF" colspan="2" nowrap align="left">
			<img src="https://central.sun.net/https%3A//swbtres.central.sun.com%3A443/bugz/images/dot.gif" width="5">
                        <TEXTAREA rows="6" cols="95" wrap="virtual" name="comments" align="left" bgcolor="white">

Name: iaR10016			Date: 07/15/2003

JCK1.5 test api/java_awt/Graphics/index.html#DrawImage[Graphics2025_14] fails with JDK1.5.0-b10 due to this bug.

Name: iaR10016			Date: 11/05/2003

JCK1.5-runtime (b07) api/java_awt/Graphics/index.html#DrawImage[Graphics2025_14] test
is in the latest JCK1.5 known failure list because of this bug.
Graphics class API Specification was changed in the latest tiger builds, so the test
should be updated to meet new Specification requirenments.
I have filed bug 4949095 about this issue.

Name: yd153349			Date: 09/10/2004

Remove  ###@###.### jck

###@###.### 2004-09-10

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: generic tiger-beta FIXED IN: tiger tiger-beta INTEGRATED IN: tiger-b26 tiger-beta VERIFIED IN: 1.5

EVALUATION Passing to 2D for their evaulatuion. ###@###.### 2002-01-03 First, there is an issue with the MediaTracker in that it was implemented to return after the "first frame" of an animated image completes. The reason this was done was that it would be impossible to wait for such an image to be "fully loaded" within the constraints of its design which relies on the ImageObserver notifications. There is currently no way within the Toolkit image code to know when all of the data for an image has been fetched so we can only infer from the FRAME and ALLBITS notifications to an observer whether the image was loaded. Note that the domain of image loading and tracking now falls under the Image I/O APIs so it is unlikely that the design of Toolkit images will ever be enhanced to make this make more sense. Given that caveat, this test case is then flawed in that it figures that the return from waitForAll() means that the image was completely loaded. It would then make sense that if the observer had been handed to a drawImage call which returned false and the image had subsequently been completely loaded then the observer must at some point be notified in some manner, but animated images break this in two ways: - They always return false from drawImage until the animation completes - They kick MediaTracker out of its wait loops after the first frame is delivered Given those 2 conditions it then follows that if an animated image is in the state of already having drawn its first frame when drawImage is called, then that drawImage will return false, and an immediately subsequent MediaTracker operation will return immediately as well and no notifications will occur in that time frame. Note that if you remove the call to drawImage(..., new Container()) from right before the loop then the test says "OKAY". The documentation for MediaTracker should really be modified to indicate that the wait routines will return when a static image is completely loaded or when a dynamic/animated image has its first frame completed. As such, I am reassigning this as a doc bug. ###@###.### 2003-03-14