是否可以将byte []转换为位图源? [英] Is it possible to convert a byte[] to a bitmapsource?

查看:79
本文介绍了是否可以将byte []转换为位图源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我有:

using (MemoryStream ms = new MemoryStream(imageData))
{
     Bitmap img = (Bitmap)Image.FromStream(ms);
}

然后我想我可以以某种方式从img获得BitmapSource?如果这是完全错误的,请随时纠正我.

And then I would imagine I would be able to get a BitmapSource from img somehow? If this is totally wrong please feel free to correct me.

推荐答案

找到最简单的解决方案:

Got the easiest solution:

using (MemoryStream ms = new MemoryStream(imageData))
{
    BitmapDecoder bitmapDecoder = BitmapDecoder.Create(ms, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
    BitmapSource photo = new WriteableBitmap(bitmapDecoder.Frames.Single());
}

还没有进行测试,但是我的代码来自:此处

Haven't tested it yet but my code was taken from: Here

这篇关于是否可以将byte []转换为位图源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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