For reading a picture from a folder with my Silverlight application, I Set the source of a Bitmap image with the stream of the file. See the code below:
string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Images", String.Format("{0}.jpg", _imageName));
if (File.Exists(path))
{
Image = new BitmapImage();
Image.SetSource(new MemoryStream(File.ReadAllBytes(path)));
}
The problem is that the image take a lot of time to show up and when I load a lot of pictures ( >400), I may get a insufficient memory error. I never had this error when loading a picture by the URI and I was wondering if it was possible to load it by the URI from a path. The code I tried:
string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Images", String.Format("{0}.jpg", _imageName));
if (File.Exists(path))
{
Image = new BitmapImage()
{
UriSource = new Uri(path),
CreateOptions = BitmapCreateOptions.DelayCreation
};
}
Do you have any hints to provide ?
Thank you!
Philippe