CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2009
    Posts
    7

    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

  2. #2
    Join Date
    Jun 2008
    Posts
    2,477

    Re: help on efficient image loading


  3. #3
    Join Date
    Feb 2009
    Posts
    7

    Re: help on efficient image loading

    I need to access the images at runtime, so embedding them in a resource file won't help.

  4. #4
    Join Date
    Jun 2008
    Posts
    2,477

    Re: help on efficient image loading

    Ahh. How long does it take on average right now? How many images will be in this directory?

  5. #5
    Join Date
    Mar 2008
    Location
    IRAN
    Posts
    811

    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]

  6. #6
    Join Date
    Aug 1999
    Location
    <Classified>
    Posts
    6,882

    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

  7. #7
    Join Date
    Feb 2009
    Posts
    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?

  8. #8
    Join Date
    Mar 2008
    Location
    IRAN
    Posts
    811

    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
  •  





Click Here to Expand Forum to Full Width

Featured