IO.Stream 到 WPF 中的图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16857325/
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
IO.Stream to Image in WPF
提问by Tanuj Wadhwa
I am trying to read an image from a resource only DLL file. I am able to read the image name and image bytes, but How do I set the Imagecontrol to stream buffer? In windows form, I know I can use this :
我正在尝试从仅资源的 DLL 文件中读取图像。我能够读取图像名称和图像字节,但是如何将Image控件设置为流缓冲区?在 Windows 窗体中,我知道我可以使用它:
pictureBox1.Image=new System.Drawing.Bitmap(IOStream);
since there is no Drawing namespace in wpf, how can I achieve the same thing?
由于 wpf 中没有 Drawing 命名空间,我该如何实现相同的功能?
采纳答案by nvoigt
回答by John Willemse
In WPF, you can set the Sourceproperty of an Image, as in this example:
在 WPF 中,您可以设置 的Source属性Image,如下例所示:
Image image = new Image();
using (MemoryStream stream = new MemoryStream(byteArray))
{
image.Source = BitmapFrame.Create(stream,
BitmapCreateOptions.None,
BitmapCacheOption.OnLoad);
}
Where byteArrayis the array of bytes with the source of the image.
byteArray带有图像源的字节数组在哪里。

