Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

BufferedImage alternative?

 
Mitchell Holmans
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I'm currently working on an app that requires me to draw two large images (15MP) which can be zoomed, panned and resized. It works fine but the images total 500MB but it uses up 3.5GB of memory, which is fine on pc for what i need it for but will probably not work too well on a mobile device. At the moment, the code loads the two BufferedImages and then draws them as necessary within a viewport on the screen. I am aware that swing essentially keeps two copies of the BufferedImage, the normal one that was loaded (in raw uncompressed format) and a second copy which is essentially what gets drawn to the screen.

So, my question is this, is there a way for me to optimize this process? As in, make it so that it does not use up enormous amounts of memory. So far i've tried using ImageReaders to subsample the image and only load in as needed but i'm sort of fumbling in the dark and it still seems to use up massive amounts of memory. If necessary i'll need to swap to another programming language (most likely C++) but i'd rather keep it in java so if anyone has any ideas, it would be very much appreciated.
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've never had occasion to use it, but I wonder if VolatileImage would help here.

Also, you can try setDoubleBuffered(false) as that should reduce the memory footprint.
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which mobile devices are you targeting? I'm not aware of any that would support any kind of Swing-based or ImageIO-based solution, irrespective of the memory requirements.
 
Mitchell Holmans
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It will be for iPhone, Android and PC but the initial PC implementation is being used to figure out how the program will work and how to deal with large images and small amounts of memory.
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the other devices don't furnish the same API, so I don't see how optimizing for a PC is going to solve anything.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic