Results 1 to 4 of 4

Thread: [RESOLVED] Loading Images;

  1. #1

    Thread Starter
    Hyperactive Member Pac_741's Avatar
    Join Date
    Jun 2007
    Location
    Mexico
    Posts
    298

    Resolved [RESOLVED] Loading Images;

    Hello, i'm developing a contacts manager that allows the user to choose a picture for the contacts, so i have a listbox, and custom listbox items, which contains a Datatemplate containing the image of the contact, so when i have more than 5 contacts my app gets kind of slow while loading the contacts, i have made several tests on how to load images quicker, but without good results.

    This is the code i use to load images from a string value which is the path of the image.

    C# Code:
    1. FileStream Strm = new FileStream((string)value, FileMode.OpenOrCreate);                  
    2.  
    3.  BitmapImage Image = new BitmapImage();
    4. Image.BeginInit();
    5. Image.CacheOption = BitmapCacheOption.OnLoad;
    6. Image.StreamSource = Strm;
    7. Image.EndInit();
    8.  
    9. Image.Freeze();
    10. Strm.Dispose();
    11. Strm.Close();
    12.  
    13. return Image;

    If someone can improve this code, or let me know about some other way to load images faster i would appreciate it.

    Thanks a lot
    C# and WPF developer
    My Website:
    http://singlebits.com/

  2. #2
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Loading Images;

    Cant you just set the image path in XAML (in your datatemplate) so that it handles all the converting etc for you? Might be a bit quicker than the way your doing it thats all.
    If thats still slow, then I guess one option is to use something like the method that you are already using but make it Asynchronous (using a background worker for example) so that the images are still loaded but the app isnt waiting for them to be loaded before it can move on to doing anything else.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  3. #3

    Thread Starter
    Hyperactive Member Pac_741's Avatar
    Join Date
    Jun 2007
    Location
    Mexico
    Posts
    298

    Re: Loading Images;

    Thanks chris128, setting the image path in XAML makes it even more slow, i'm using the code i posted in a converter that returns a bitmapimage from a memorystream containing all byes from an image.

    Thanks for the idea of using background worker, i will try that.
    C# and WPF developer
    My Website:
    http://singlebits.com/

  4. #4

    Thread Starter
    Hyperactive Member Pac_741's Avatar
    Join Date
    Jun 2007
    Location
    Mexico
    Posts
    298

    Re: Loading Images;

    Nevermind, the problem is another part of my application

    thanks anyway.
    C# and WPF developer
    My Website:
    http://singlebits.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