|
-
February 7th, 2009, 01:52 PM
#1
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.
Last edited by blabla2006; February 7th, 2009 at 02:00 PM.
Reason: Adding Framework version
-
February 7th, 2009, 07:02 PM
#2
Re: help on efficient image loading
-
February 8th, 2009, 12:29 AM
#3
Re: help on efficient image loading
I need to access the images at runtime, so embedding them in a resource file won't help.
-
February 8th, 2009, 06:05 AM
#4
Re: help on efficient image loading
Ahh. How long does it take on average right now? How many images will be in this directory?
-
February 9th, 2009, 01:22 PM
#5
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.
Please rate my post if it was helpful for you.  Java, C#, C++, PHP, ASP.NET
SQL Server, MySQL
DirectX
MATH Touraj Ebrahimi
[toraj_e] [at] [yahoo] [dot] [com]
-
February 10th, 2009, 04:31 AM
#6
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.
Regards,
Ramkrishna Pawar
-
February 10th, 2009, 09:53 AM
#7
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?
-
February 10th, 2009, 01:54 PM
#8
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.
Please rate my post if it was helpful for you.  Java, C#, C++, PHP, ASP.NET
SQL Server, MySQL
DirectX
MATH Touraj Ebrahimi
[toraj_e] [at] [yahoo] [dot] [com]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|