C# Answers Forum - how do you load a bitmapimage in wpf?

The Artima Developer Community
Sponsored Link

C# Answers Forum
how do you load a bitmapimage in wpf?

3 replies on 1 page. Most recent reply: May 12, 2019 10:40 PM by vinicius santos

Welcome Guest
Sign In

Flat View: This topic has 3 replies on 1 page
William Thompson

Posts: 11
Nickname: xarzu
Registered: Nov, 2007

how do you load a bitmapimage in wpf? Posted: Aug 3, 2012 7:44 AM
Advertisement
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


Priya Arrora

Posts: 5
Nickname: priya456
Registered: Aug, 2017

Re: how do you load a bitmapimage in wpf? Posted: Aug 21, 2017 12:09 AM
You can use the constructor to specify the UriSource

BitmapImage bmp = new BitmapImage(uriSource: new Uri());

Or you can use BitmapImage.StreamSource property to set the StreamSource

aer aer

Posts: 3
Nickname: zoziano
Registered: Oct, 2018

Re: how do you load a bitmapimage in wpf? Posted: Oct 13, 2018 11:02 AM
I'm trying this code, but I need some help to get it to work. I get some red lines below the code! I also wonder if I need to add some extra code inside the XAML code or is in enough with this:

vinicius santos

Posts: 1
Nickname: destroi
Registered: May, 2019

Re: how do you load a bitmapimage in wpf? Posted: May 12, 2019 10:40 PM
I'm trying this code, but I need some help to get it to work.











Redtube
pornhub
xvideos

Flat View: This topic has 3 replies on 1 page

Sponsored Links



Web Artima.com

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use

AltStyle によって変換されたページ (->オリジナル) /