How to convert System.IO.Stream into an Image?

2020-05-31 04:04发布

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?

4条回答
Viruses.
2楼-- · 2020-05-31 04:29

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

查看更多
神经病院院长
3楼-- · 2020-05-31 04:35

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);
查看更多
做个烂人
4楼-- · 2020-05-31 04:41

For phone this should work:

BitmapImage image = new BitmapImage();
image.SetSource(stream);
查看更多
冷血范
5楼-- · 2020-05-31 04:48

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.
查看更多
登录 后发表回答