简体   繁体   中英

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

如何将图像Stream (我使用MediaLibraryAlbum.GetArt方法检索到)转换为应用程序中的可用Image

简单... var img = Bitmap.FromStream(stream);

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);

For phone this should work:

BitmapImage image = new BitmapImage();
image.SetSource(stream);

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM