How do I load a bitmap in WPF?

Posted by Zhang Jingchu under C# on 8/2/2012 | Points: 10 | Views : 2104 | Status : [Member] | Replies : 1
In a silverlight app, I have a BitmapImage defined as System.Windows.Media.Imaging.BitmapImage and it as a method called "SetSource" where I can set the source like this:

BitmapImage bitmap = new BitmapImage(); 
System.IO.Stream stream = _scene.GetStream();
if (stream == null) return;
bitmap.SetSource(stream);


In a WPF application I have also have a Bitmap image defined as System.Windows.Media.Imaging.BitmapImage but there is no SetSource method. How do I set the source in a WPF app like I do in a Silverlight app?

Also, it is a stream, not a string. It is not a URI. so "UriSource" method does not work. I tried this:
        System.IO.Stream stream = _scene.GetStream(); 
if (stream == null) return;
BitmapImage bitmap = new BitmapImage();

bitmap.UriSource = new Uri(stream.ToString());


And at runtime, it threw an error tha URI cannot be determined. Is the URI an identifier for the intranet? Are you sure that this is not a silverlight thing? I am doing a WPF application




Responses

Posted by: Rajkatie on: 8/2/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Refer following link

http://www.i-programmer.info/programming/wpf-workings/520-bitmapimage-and-local-files-.html


Rajesh Patel
.Net Trainer(M.C.S.A | MCT)
Brainbench (Asp.Net 4.5 and C# 5.0)

Zhang Jingchu, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response