F
Frank LaRosa
What's the right way to wait for an image to be fully loaded?
I have a non-GUI application (it's a servlet that is trying to load an
image file into memory and crop or scale it). I'm using
TookKit.createImage(byte[]) to make the image. The bytes are the
contents of a GIF or JPEG image loaded from a file.
I'm aware that images are loaded asynchronously, so I wrote some code
to use a MediaTracker to wait for the image to be fully loaded. My
code looks like this:
MediaTracker tracker = new MediaTracker(new Container());
tracker.addImage(image, 0);
if (!tracker.checkID(0, true)) {
tracker.waitForID(0);
}
Sometimes it works fine, and other times, the "waitForID" call never
returns. I can't figure out why. It works and then fails with the same
images. Also, when it fails, my CPU useage goes up to 100% and stays
there until I kill the JVM.
Is there something I need to do to initialize the graphics
environment? I'm using JDK 1.4.2_02 with the
"-Djava.awt.headless=true" option, and I'm running it on Windows with
Orion server. There is no actual window or GUI involved.
Thanks.
I have a non-GUI application (it's a servlet that is trying to load an
image file into memory and crop or scale it). I'm using
TookKit.createImage(byte[]) to make the image. The bytes are the
contents of a GIF or JPEG image loaded from a file.
I'm aware that images are loaded asynchronously, so I wrote some code
to use a MediaTracker to wait for the image to be fully loaded. My
code looks like this:
MediaTracker tracker = new MediaTracker(new Container());
tracker.addImage(image, 0);
if (!tracker.checkID(0, true)) {
tracker.waitForID(0);
}
Sometimes it works fine, and other times, the "waitForID" call never
returns. I can't figure out why. It works and then fails with the same
images. Also, when it fails, my CPU useage goes up to 100% and stays
there until I kill the JVM.
Is there something I need to do to initialize the graphics
environment? I'm using JDK 1.4.2_02 with the
"-Djava.awt.headless=true" option, and I'm running it on Windows with
Orion server. There is no actual window or GUI involved.
Thanks.