Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Question about rescaling/rendering lots of big pictures  RSS feed

 
Michael Phospere
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically what I'm working with is a situation where I need to be able to rescale and render a large amount (several hundred) images from a digital camera (1600x1200) into a viewerable thumbnail-size. The rescaling is dynamic and for intents and purposes happens on a resize of the viewing window.
I've been scouring the web for information and trying out different approaches, but so far, all I've ran into are brick walls.
The first approach is:
1) Retrieve the image from the .jpg with Toolbox.getImage()
2) Draw the image by overriding paint() with graphics.drawImage(xpos, ypos, xwidth, ywidth...) where xwidth and ywidth are the desired dimensions of the picture at the time of drawing.
From testing, it seems that regardless the scaling, there's a memory hit proportionate to the size of the Image object used to draw the image. When rendering a number of images of this size, this results in an OutOfMemory error when paint() is called.
The second approach is:
1) Retrieve the image from the .jpg with Toolbox.getImage().
2) On a resize call, create a scaled instance of the image using Image.getScaledInstance().
3) Override paint() to draw the scaled instance of the image isntead of the original image.
The method seems to take care of the OutOfMemory errors for the most part. However, there is a very noticable performance hit associated with setting up the scaled instance.
Any thoughts or ideas on this? I'm not sure if there's any other way around this =x
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are always going to have the memory hit the first time you load an image. (Unless you save off a thumbnailed image after you create it once... tradoff of diskspace for speed.) I would leave out the rescaling when the app changes size... you are going to have a massive memory hit every time because all the gigantic images have to be reloaded and thumbnails made of them again. There's no real "value added" for this feature either... if anything, I'd just let the user choose the size they wanted the thumbnails to be...
 
Michael Phospere
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, to get a little more detailed, only a handful of images dynamically resize with the frame. The rest are indeed collectively resized by user input.
Writing jpgs to disk to save memory was my last idea, but it seems like that this is too "easy" of a task to be resorting to writing to disk. Dunno though, I'll have to try tonight.
My biggest concern was the performance hit involved because the app has to run fast, but it looks like there's no way around it?
[ July 21, 2003: Message edited by: Michael Phospere ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!