help on efficient image loading
I'm writing a program which runs on a specific directory with images, reads them to a Bitmap file and then resize them, and add the resized image to a Bitmap hashmap. The naive code to do this is like this:
Bitmap bmp = new Bitmap(flFileArray[i].FullName);
Bitmap bmp2 = new Bitmap(bmp, (int)(nudWidth.Value / nudNumOfPics.Value),
(int)(nudHight.Value / nudNumOfPics.Value));
m_hshBitmapArray.Add(bmp2, GetAvgPixelVal(bmp2));
It's quite simple, but i'm wondering if there is a faster way to do this. Can anyone think of something?
BTW, Im coding on VS2008, but it wouldn't hurt getting an answer for VS 2005.
Re: help on efficient image loading
Re: help on efficient image loading
I need to access the images at runtime, so embedding them in a resource file won't help.
Re: help on efficient image loading
Ahh. How long does it take on average right now? How many images will be in this directory?
Re: help on efficient image loading
if i were you i do it like this using multi-threading.
1- Thread1: reading image and resizing them then adding them into the queue
2- Thread2: deguing images from the queue and adding them to the hashmap
3- Thread Safty: i implement Mutex objet for locking on queue or Semaphore if i needed somehow more than one thread enter the critical section of my code.
Re: help on efficient image loading
Threading wouldn't make it faster, the file load can not be avoided, which is a major time consuming call.
Re: help on efficient image loading
My code works quite well, but i need to access thousands of images of various sizes, so every bit of tweaking can be good.
The use of multi-threading is interesting, this way i can load images and compute their avg pixel values "simultaneously" . But is there a better way to load thousands of images and then resizing them? A structure better than Bitmap say? A better method?
Re: help on efficient image loading
i don't think there are any special tweak except multi-threading if it works fine for you in practice.