[.net] I need a trick [help request]

Started by
9 comments, last by GameDev.net 17 years, 8 months ago
Hi guys, In my program I want to view thumbnails.. But when the original image size goes up the program starts to freeze.. In my method I directly load the original image to an Image object and then using the GetThumbnail(....) method resize it and pass to another Image object. But it seems this is not an effective way !! Is there ny idea, or trick or something else to increase this performance ? I am open to any advice.. Best regards
Advertisement
Doing some of that work in another thread should improve responsiveness, even if the work itself will take just as long (if not longer).
You mean -lets say- if I have 1000 images to load, then split them -again lets say- in wihch each part have 50 images and load them with 20 threads working parallely ?
Just one thread will do, to much is overkill. So create just one loader thread, which will load all the images you need, be it 1000 - 10000.

If you're using C# this link will keep you busy for a while:

MSDN C# Threading

Next time I give my advice, I'll buy some bubblegum so I won't your kick ass!
You are right but this will not improve my performance, just make the main form not to freeze (stay inresponsive) but the loading will still take too much time..

By the way, the help I am requesting for is a pattern, a methodology or something like this to improve my performance. I am sure that I am doing something wrong, there must be some other way to make an image's thumbnail and view it.. :S
What format is the original image in?

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

Well, the images mainly will directly be loaded from a camera, I guess their format will .bmp,.tiff or .jpeg, but at least I am sure that there will not be only one format because the application will also read from CD/DVD, Removable media or Harddisks.. So any image format will be used >S
If you've ever browsed a folder in windows thats full of images (in thumbnail mode) you'll see it takes a long time to load all the images.
The trick is to prioritise which images to thumbnail - based on what images the user is trying to see (ie, where they've scrolled to). Also, show a temporary file.
People are used to it taking a long time to load a lot of images.

Wyzfen
well for example for 187 .jpg images (365 MB) it takes 1 min 17 secs to load.. this is not normal I think ;|
So here are some hints:
- use a worker thread as was already suggested to load an image and create a thumbnail of it
- have a queue of jobs for the worker thread for the images that need to be converted to a thumbnail, this way the application can reorder the creation of thumbnails or stop it
- put the images that are currently visible in that queue first
- store the thumbnails in a cache (maybe a hidden file) so that they don't need to be recreated each time, index the files in the cache by the absolute filename or by the basename + hash of file contents (or maybe the first 100 bytes of the file instead of a hash)
- give the worker thread a lower priority then the gui thread, if the worker thread is eating up 100% of its time slices it will get any available cpu cycles while the gui still stays responsive
- you may want two have two worker threads instead of one, so that not only the cpu is better utilized but also the harddisk/cd/dvd/whatever, one thread loads the images while the other one converts them in the meantime
- depending on the image file format you may want to provide different methods for thumbnail creation, for instance a jpeg the is compressed in progressive mode already contains a low-res version

This topic is closed to new replies.

Advertisement