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
How to convert System.IO.Stream into an Image?
提问by Newbie
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?
如何将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.