我正在尝试从纯资源 DLL 文件中读取图像。我能够读取图像名称和图像字节,但是如何将 Image
控件设置为流缓冲区?在 Windows 窗体中,我知道我可以使用这个:
pictureBox1.Image=new System.Drawing.Bitmap(IOStream);
既然wpf中没有Drawing命名空间,我该如何实现呢?
最佳答案
在 WPF 中,您可以设置 Image
的 Source
属性,如本例所示:
Image image = new Image();
using (MemoryStream stream = new MemoryStream(byteArray))
{
image.Source = BitmapFrame.Create(stream,
BitmapCreateOptions.None,
BitmapCacheOption.OnLoad);
}
其中 byteArray
是包含图像源的字节数组。
关于c# - IO.Stream 到 WPF 中的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16857325/