views:

45

answers:

1

Hi,

I need the functionality to show large images on a Java Applet without increasing the default heap space. I'm getting the "Out of memory" exception when reading the large image using ImageIO.read() into a BufferedImage (what was expected to happen).

To solve this issue, the first thing that comes to mind is to divide the large image into lesser parts.

My question is:

Does anyone have some tips on which direction to take to implement this functionality (which includes showing the correct part when scrolling the image)? Does Java have anything built-in to support this? Any examples?

+1  A: 

You must work with parts. The simplest is to have the server provider smallish tiles you Can request As needed.

If not you must dó it yourself in the applet. Load the image - split it in tiles and have each tile reencode itself to a bytestream e.g as jpeg. Attach the rendered tile as a soft reference so it Will be garbage collected as late as possible. If the rendered tile has been gc'ed then decode the jpeg bytestream.

If you have a LOT then even consider serializong tiles to local storage.

Thorbjørn Ravn Andersen
Do you know (by coincidence) how to read an image without using the default ImageIO.read() function (which is causing the exception)?
Zurb
If it is so large you cannot even render a single image, you must dó this server-side. Also check JIMI from SUn
Thorbjørn Ravn Andersen
Unless the OP is using JDK < 1.4 (which I'm pretty sure he's not, since he's using ImageIO which is 1.4+), he should probably stick to ImageIO since it has replaced JIMI (which is no longer shipped with the JDK).
laginimaineb
@laginimaineb, JIMI has never shipped with a JDK, and I believe it allows for decoding to something else than an Image which might even be smaller.
Thorbjørn Ravn Andersen
@Thorbjørn, you're right, no idea why I was under that impression o.O
laginimaineb