views:

158

answers:

1

Hello,

I am trying to load a 3776 * 2816 PNG, 24 bit image - 804KB onto my phone , the MOTO ROKR e6.It gives up with java.lang.OutOfMemoryError,Is their a general way to handle loading such high resolution images.The phone's internal memory is only 8MB, I think this has something to do with the error.

I have also, tried to split the image to 16 parts and load them, still there seems to be some limit on what it can handle.

Please advise.

+1  A: 

So just some quick calculations:

24 bits = 3 bytes
space required (in bytes) = 3776 * 2816 * 3 
                          = 31,899,648 bytes
                          = 31.9MB

That means once you've loaded the image (using ImageIO or JAI or whatever) you need 31.9MB to store the raw image data. As a result you can't load it on a device with only 8MB of memory (and I'm assuming no other kind of swap space).

You could load the raw file as bytes of data rather than an image -- the data is heavily compressed -- but I don't think that's what you're looking for.

Mark E
So,it looks like there is no way to load the image :( .Guess my phone's old. I was trying to write an application similar to google maps for displaying this high resolution static image that I could zoom out/in.
panzerschreck
You could try tiling the image into smaller segments, and then load relevant segments. If you're building a zoom application you could consider building multiple images at varying resolution (by downsampling) before loading them onto your phone.
Mark E