C# 如何将 System.IO.Stream 转换为图像?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18134234/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 11:24:19  来源:igfitidea点击:

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

c#imagewindows-phone-7windows-phone-8stream

提问by Newbie

How can I convert a Streamof an image (which I retrieved using the Album.GetArtmethod from the MediaLibrary) into a usable Imagein my application?

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

采纳答案by I4V

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

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

回答by Jim O'Neil

For phone this should work:

对于电话,这应该有效:

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

回答by Chris Schiffhauer

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

回答by JOSMAR BARBOSA - M4NOV3Y

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.