Ways to interrupt loading of large images

W

William Rose

Hi,

I'm looking for ways to interrupt the loading of a large image from a
remote site. The simple way to load such an image is obviously to use
Toolkit getImage/createImage with a URL parameter. The less simple way
is to manage the download oneself and get a byte array, and pass that to
createImage.

Once that's done though (createImage( byte[] )), it seems there's no way
to prevent full decoding of the image. Does anyone know a way around
this? Because it seems that this can take a non-trivial amount of time
for a large image, so it would be nice to abort it if possible.

cheers,
Will
 
P

Paul Lutus

William said:
Hi,

I'm looking for ways to interrupt the loading of a large image from a
remote site. The simple way to load such an image is obviously to use
Toolkit getImage/createImage with a URL parameter. The less simple way
is to manage the download oneself and get a byte array, and pass that to
createImage.

Once that's done though (createImage( byte[] )), it seems there's no way
to prevent full decoding of the image. Does anyone know a way around
this? Because it seems that this can take a non-trivial amount of time
for a large image, so it would be nice to abort it if possible.

You could always write your own decoding algorithm, place the decoding
activity in a separate thread, and have the thread (and the algorithm)
monitor an external flag that commands it to pause or abort.

This may sound like a strange solution, but since the Java library decoders
are not written in native code any more, there shouldn't be much speed
difference if you write your own. The JPEG decoder in particular is
extremely slow, and it happens I have an application with the same problem.
 
B

Babu Kalakrishnan

William said:
I'm looking for ways to interrupt the loading of a large image from a
remote site. The simple way to load such an image is obviously to use
Toolkit getImage/createImage with a URL parameter. The less simple way
is to manage the download oneself and get a byte array, and pass that to
createImage.

Once that's done though (createImage( byte[] )), it seems there's no way
to prevent full decoding of the image. Does anyone know a way around
this? Because it seems that this can take a non-trivial amount of time
for a large image, so it would be nice to abort it if possible.

Have you tried reading in the image using the classes from the javax.imageio
package ? The ImageReader class (which is the super class of all actual
implementations) has an "abort()" method that is supposed to provide this
functionality. (Never tried it myself - so not sure how the implementations
supplied in the library really behave).

BK
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top