I use the following code for the image source stream:
BitmapImage Art3 = new BitmapImage(); using (FileStream stream = File.OpenRead("c:\\temp\\Album.jpg")) { Art3.BeginInit(); Art3.StreamSource = stream; Art3.EndInit(); } artwork.Source = Art3;
"artwork" is the XAML object in which the image should be displayed. The code should not block the image, it does not block it in order, but does not display it, and the default image becomes โnothingโ ... I assume that I am using the stream incorrectly and that my image becomes null. Help?
UPDATE:
Now I use the following code that a friend suggested to me:
BitmapImage Art3 = new BitmapImage(); FileStream f = File.OpenRead("c:\\temp\\Album.jpg"); MemoryStream ms = new MemoryStream(); f.CopyTo(ms); f.Close(); Art3.BeginInit(); Art3.StreamSource = ms; Art3.EndInit(); artwork.Source = Art3;
For some strange reason, this code returns the following error:
Image cannot be decoded. Image title may be corrupted.
What am I doing wrong? I am sure that the image I'm trying to download is not corrupted.
source share