加载一个byte []成运行时图像 [英] Load a byte[] into an Image at Runtime

查看:116
本文介绍了加载一个byte []成运行时图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字节[] 是由图像表示。我通过 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆