Picture scaling - memory issues

J

jonck

Hi,
In my app people can load a picture, which I then show in a scaled down
version. To do the scaling I follow the sample code as shown here:
http://javaalmanac.com/egs/java.awt.image/CreateTxImage.html

All this works fine, though sometimes if a user loads in a very large
pictuer I get an OutOfMemory error. Now ideally what I would like to do
is test before the picture is loaded whether there is enough memory
available to do the operation. In order to do that I would need to get
an idea of how much memory will be needed to do the scaling.
Does anyone know what (roughly) the proportion is of memory used to the
size and depth of the picture?

Thanks, Jonck
 
T

Thomas Weidenfeller

jonck said:
All this works fine, though sometimes if a user loads in a very large
pictuer I get an OutOfMemory error. Now ideally what I would like to do
is test before the picture is loaded whether there is enough memory
available to do the operation.

This is in general unpredictable. During the (small) time between your
test for memory and the loading of the image some other process might
have gotten the memory. So even if your test tells you that there is
enough memory, you application might fail later.

/Thomas
 
B

Boudewijn Dijkstra

jonck said:
Hi,
In my app people can load a picture, which I then show in a scaled down
version. To do the scaling I follow the sample code as shown here:
http://javaalmanac.com/egs/java.awt.image/CreateTxImage.html

All this works fine, though sometimes if a user loads in a very large
pictuer I get an OutOfMemory error.

There are algorithms that don't have to load the entire image before scaling
begins.
Now ideally what I would like to do
is test before the picture is loaded whether there is enough memory
available to do the operation. In order to do that I would need to get
an idea of how much memory will be needed to do the scaling.
Does anyone know what (roughly) the proportion is of memory used to the
size and depth of the picture?

1
 
B

Boudewijn Dijkstra

Boudewijn Dijkstra said:
There are algorithms that don't have to load the entire image before scaling
begins.


1

Unless of course you have the image in video memory, in which case the rough
proportion is 0.
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top