We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,595 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

How do you set the source of a Bitmap Image in WPF?

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

1
Contributor
0
Replies
1
View
complete
Junior Poster
170 posts since Dec 2005
Reputation Points: 17
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0518 seconds using 2.71MB