Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

How Do I load a BitmapImage in WPF?


  • Please log in to reply
1 reply to this topic

#1 XARZU

XARZU

  • Members
  • 22 posts
  • OFFLINE
  •  
  • Local time:05:27 PM

Posted 03 August 2012 - 10:34 AM

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

BC AdBot (Login to Remove)

 


#2 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:03:27 PM

Posted 03 August 2012 - 11:41 AM

Use the StreamSource property: http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapimage.streamsource.aspx

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users