Skip to main content

Applet.getImage does not return immediately as said in the API doc

2 replies [Last post]
25or6to4
Offline
Joined: 2008-09-07
Points: 0

The API documentation for Applet.getImage says:
This method always returns immediately, whether or not the image exists.
When this applet attempts to draw the image on the screen, the data will be loaded.
The graphics primitives that draw the image will incrementally paint on the screen.

This is not true with Java Plug-in 1.6.0_10-rc2, as shown in the applet below.
It has been tested with Java Plug-in 1.6.0_01 and Java Plug-in 1.6.0_10-rc2.
The applet has been compiled with jdk1.6.0_03 and run in IE 6.0.2900.5512 SP3
on Windows XP SP3.
The tests were made using a dial-up connection, the ouput shows 9 sec for
getImage to return. Even on a slow connection, it should return immediately.
Really inconvenient!

************ 3 tests with 1.6.0_01 ***********
Java Plug-in 1.6.0_01
Using JRE version 1.6.0_01 Java HotSpot(TM) Client VM

After clearing the plug-in cache
getImgage(image1.jpg) took 0 millis.

2nd test without clearing the cache from previous test
getImgage(image1.jpg) took 0 millis.

3rd test without clearing the cache from previous 2 tests
getImgage(image1.jpg) took 0 millis.

*********** 3 tests with 1.6.0_10-rc2 ***********
Java Plug-in 1.6.0_10-rc2
Using JRE version 1.6.0_10-rc2 Java HotSpot(TM) Client VM

After clearing the plug-in cache
getImgage(image1.jpg) took 9000 millis.

2nd test without clearing the cache from previous test
getImgage(image1.jpg) took 9016 millis.

3rd test without clearing the cache from previous 2 tests
getImgage(image1.jpg) took 9000 millis.

// ---------------------------------------------------------------------
import java.applet.*;
import java.awt.*;
import java.awt.image.*;

public class GetImageBug extends Applet implements ImageObserver
{
   public void init()
   {
      String image1Name = "image1.jpg";
      long time0 = System.currentTimeMillis();
      Image image1 = getImage(getCodeBase(), image1Name);
      System.out.println("getImgage(" + image1Name + ") took " +
         (System.currentTimeMillis()-time0) + " millis.");
      prepareImage(image1, this);
   }

   public boolean imageUpdate(Image img, int  infoflags,
      int  x, int  y, int  width, int  height)
   {
      if ( (infoflags & ImageObserver.ALLBITS) != 0 )
         return false;
      return true;
   }
}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
fatbatman
Offline
Joined: 2004-12-24
Points: 0

Yea we had problems with getImage() within a real world situation and so stopped using it.

From what I remember things seemed to lock up for periods when multiple images were being loaded at the same time. We now use our own custom MyImageLoader wrapper class that uses ImageIO.read() underneath to load images in seperate threads. This works much better, although we have a problem where ImageIO.read() is not returning accelerated images by default, so to copy each image into a newly created accelerated image. We use lots of images (socialbang.com) so this slows things down.

See http://forums.sun.com/thread.jspa?messageID=10423950

fatbatman
Offline
Joined: 2004-12-24
Points: 0

Can anyone confirm if ImageIO.read() should return an accelerate image by default if available? as described at http://forums.sun.com/thread.jspa?messageID=10423950 Should this be filed as a bug?

I haven't tested if Applet.getImage() returns an accelerated image by default or not, because it's too slow to use as described above, has this been filed as a bug?