How Do I load a bitmapImage in WPF?

August 3, 2012 at 08:52:13
Specs: Windows 7
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


See More: How Do I load a bitmapImage in WPF?

Report •

#1
August 3, 2012 at 09:58:34
Are you sure it's not there? PowerShell tells me otherwise.
PS C:\> New-Object System.Windows.Media.Imaging.BitmapImage | `
gm |? { $_.Name -eq "StreamSource" }


   TypeName: System.Windows.Media.Imaging.BitmapImage

Name         MemberType Definition                              
----         ---------- ----------                              
StreamSource Property   System.IO.Stream StreamSource {get;set;}

Is the URI an identifier for the intranet?
URI = Uniform resource identifier. If it's a file, or if it's presented to you as a file, then you can use a URI.

How To Ask Questions The Smart Way


Report •
Related Solutions


Ask Question