|
-
Mar 13th, 2009, 07:30 PM
#1
Thread Starter
Hyperactive Member
[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:
FileStream Strm = new FileStream((string)value, FileMode.OpenOrCreate);
BitmapImage Image = new BitmapImage();
Image.BeginInit();
Image.CacheOption = BitmapCacheOption.OnLoad;
Image.StreamSource = Strm;
Image.EndInit();
Image.Freeze();
Strm.Dispose();
Strm.Close();
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
-
Mar 14th, 2009, 04:09 PM
#2
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.
-
Mar 14th, 2009, 05:36 PM
#3
Thread Starter
Hyperactive Member
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.
-
Mar 14th, 2009, 07:05 PM
#4
Thread Starter
Hyperactive Member
Re: Loading Images;
Nevermind, the problem is another part of my application
thanks anyway.
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
|