Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image.FromStream() in C#

Tags:

c#

image

wpf

I work in VS 2010, .Net 4.0. In Windows forms app, this is ok:

Image img = Image.FromStream(imagePart.GetStream());

However, in Wpf app, the Image class is from System.Windows.Controls and that isn't valid because it hasn't got a definition for FromStream method. In Windows forms, the Image class is System.Drawing.Image.

Is there a way I can use FromStream in Wpf app?

like image 584
petko_stankoski Avatar asked Sep 21 '26 15:09

petko_stankoski


1 Answers

In WPF I believe you'd use a BitmapSource such as BitmapImage - and in the latter case, you can set the StreamSource property to the appropriate stream.

EDIT: BitmapSource is just one subclass of ImageSource. Use a source by creating an Image control and setting the Source property.

like image 141
Jon Skeet Avatar answered Sep 24 '26 04:09

Jon Skeet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!