Click to See Complete Forum and Search --> : preload images


zhcai
April 7th, 1999, 02:17 PM
Dear java gurus,

I have a question about "Preloading Image
using JAVA". Right now I am using hetImage() and MediaTracker to
preload the image into memory like this:

img = Toolkit.getDefaultToolkit().getImage(imageURL);
// wait until the whole image is loaded
tracker.addImage(img, 0);
try {
do {
//Start downloading the images. Wait until they're loaded.
tracker.waitForAll();
} while (!tracker.checkAll());
} catch (InterruptedException e) {
System.out.println("Image is not loaded.");
return false;
}

But, it still takes lot of time to paint the img to screen using
g.drawImage(). Is there a way to preload images to memory so I can
save the time to paint them to screen? Do I have to use
prepareImage()? Thanks.

Looking forward to your help,


Joe Cai