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?
Asked
Active
Viewed 7.1k times
22

Newbie
- 1,160
- 2
- 11
- 24
4 Answers
36
Easy... var img = Bitmap.FromStream(stream);

I4V
- 34,891
- 6
- 67
- 79
-
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) – Newbie Aug 08 '13 at 19:23
-
You can also use var image=System.Net.Mime.MediaTypeNames.Image.FromStream(stream); – Nitin Dominic Mar 05 '14 at 06:15
15
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);

Chris Schiffhauer
- 17,102
- 15
- 79
- 88
4
For phone this should work:
BitmapImage image = new BitmapImage();
image.SetSource(stream);

Jim O'Neil
- 23,344
- 7
- 42
- 67
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.

Juan
- 4,910
- 3
- 37
- 46