Click to See Complete Forum and Search --> : help on efficient image loading
blabla2006
February 7th, 2009, 12:52 PM
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.
BigEd781
February 7th, 2009, 06:02 PM
Why not embed the images into the resource file? (http://support.microsoft.com/kb/319292)
blabla2006
February 7th, 2009, 11:29 PM
I need to access the images at runtime, so embedding them in a resource file won't help.
BigEd781
February 8th, 2009, 05:05 AM
Ahh. How long does it take on average right now? How many images will be in this directory?
toraj58
February 9th, 2009, 12:22 PM
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.
Krishnaa
February 10th, 2009, 03:31 AM
Threading wouldn't make it faster, the file load can not be avoided, which is a major time consuming call.
blabla2006
February 10th, 2009, 08:53 AM
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?
toraj58
February 10th, 2009, 12:54 PM
i don't think there are any special tweak except multi-threading if it works fine for you in practice.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.