Down/Up scale hi-res images in JavaFX?
891716Aug 16 2012 — edited Aug 21 2012Hello,
I plan to write an image viewer application in JavaFX. The problem is I would like also to load hi-res images ( like Windows Photo, acdsee viewer does ) without eating up a lot of memory. Currently, with the default heap size, I receive a OutOfMemoryException for an image 10000 x 5000 pixels. If I increase the heap size to 512 then it's ok ( although pretty slow loading ) but of course the memory consumption is 477 MB. I don't like this solution that much because the JVM crashes if you try to set a value greater that the physical RAM so I would need to write a native program that gets the physical RAM size, and then pass an amount percentage when launching my application using java -jar ... Also If a user has 256MB RAM then all would be in vain...
Basically I want to scale the image to default screen size resolution but allow the user to upscale the image ( zoom in ) if he wants to. In a Swing based app I probably would use an ImageReader, get the image resolution and then subsample it to obtain my desired resolution. I don't want to use that cause it's pretty slow and also I would need conversion to/from awt BufferedImage. Can someone give me some hints on how I could do this in Java FX 2, because I don't want to create an application that would crash if an image too big was loaded.
Regards,
Aurelian