Image creation performance / image caching
Posted
by Kilnr
on Stack Overflow
See other posts from Stack Overflow
or by Kilnr
Published on 2010-04-14T14:00:06Z
Indexed on
2010/04/14
14:03 UTC
Read the original article
Hit count: 206
Hello,
I'm writing an application that has a scrollable image (used to display a map). The map background consists of several tiles (premade from a big JPG file), that I draw on a Graphics object.
I also use a cache (Hashtable), to prevent from having to create every image when I need it. I don't keep everything in memory, because that would be too much.
The problem is that when I'm scrolling through the map, and I need an image that wasn't cached, it takes about 60-80 ms to create it. Depending on screen resolution, tile size and scroll direction, this can occur multiple times in one scroll operation (for different tiles). In my case, it often happens that this needs to be done 4 times, which introduces a delay of more than 300 ms, which is extremely noticeable.
The easiest thing for me would be that there's some way to speed up the creation of Images, but I guess that's just wishful thinking...
Besides that, I suppose the most obvious thing to do is to load the tiles predictively (e.g. when scrolling to the right, precache the tiles to the right), but then I'm faced with the rather difficult task of thinking up a halfway decent algorithm for this.
My actual question then is: how can I best do this predictive loading? Maybe I could offload the creation of images to a separate thread? Other things to consider?
Thanks in advance.
© Stack Overflow or respective owner