How to convert System.IO.Stream into an Image?
Asked Answered
G

4

23

How can I convert a Stream of an image (which I retrieved using the Album.GetArt method from the MediaLibrary) into a usable Image in my application?

Garrettgarrick answered 8/8, 2013 at 19:15 Comment(0)
G
38

Easy... var img = Bitmap.FromStream(stream);

Granado answered 8/8, 2013 at 19:20 Comment(2)
Bitmap doesn't seem to be a valid type? is there a reference & using I should add? (im using Windos phone 7 by the way)Garrettgarrick
You can also use var image=System.Net.Mime.MediaTypeNames.Image.FromStream(stream);Nicknickel
M
16

You can run from Bitmaps straight into the arms of Images.

Image image = System.Drawing.Image.FromStream(stream);

From whence you can do other operations:

image.Save(System.IO.Path.GetPathRoot() + "\\Image.jpg", ImageFormat.Jpeg);
Malkamalkah answered 9/8, 2013 at 0:7 Comment(0)
E
4

For phone this should work:

BitmapImage image = new BitmapImage();
image.SetSource(stream);
Eckenrode answered 9/8, 2013 at 0:0 Comment(0)
F
2

Great job! I tested this with:

Stream streamF = new MemoryStream(); // stream stored in a data file ( FileDB).


Bitmap image = new Bitmap(streamF);
ConsoleWriteImage(image);

//REMEMBER = in console App you must use < using System.Drawing; >
//to handle images but you can't use Form class for present image into some Canvas.
Fieldsman answered 30/10, 2016 at 19:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.