加载一个byte []成运行时图像 [英] Load a byte[] into an Image at Runtime
问题描述
我有一个字节[]
是由图像表示
。我通过 Web客户端
下载此图片
。当 Web客户端
已下载的图片,我使用它的URL引用它,我得到一个字节[]
。我的问题是,我怎么加载字节[]
到图片
在WPF元素?谢谢
I have a byte[]
that is represented by an Image
. I am downloading this Image
via a WebClient
. When the WebClient
has downloaded the picture and I reference it using its URL, I get a byte[]
. My question is, how do I load a byte[]
into an Image
element in WPF? Thank you.
的注意的:这是我在这里问的问题补充:的在运行时生成的图像。我似乎无法得到的工作方式,所以我尝试了不同的方法。
Note: This is complementary to the question I asked here: Generate Image at Runtime. I cannot seem to get that approach to work, so I am trying a different approach.
推荐答案
您可以使用的 的BitmapImage
,并设置其 的StreamSource
包含二进制数据流。如果你想使一个流
从字节[]
,使用的 的MemoryStream
:
You can use a BitmapImage
, and sets its StreamSource
to a stream containing the binary data. If you want to make a stream
from a byte[]
, use a MemoryStream
:
MemoryStream stream = new MemoryStream(bytes);
这篇关于加载一个byte []成运行时图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!