如何从类型图像转换成键入的BitmapImage? [英] How to convert from type Image to type BitmapImage?

查看:130
本文介绍了如何从类型图像转换成键入的BitmapImage?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道如何创建从图像的BitmapImage?这里是code,我正在与:

Does anyone know how to create a BitmapImage from an Image? Here is the code that I'm working with:

MemoryStream memStream = new MemoryStream(bytes);
Image img = Image.FromStream(memStream);

现在我有机会获得这一形象在内存中。问题是我需要将其转换为BitmapImage的才能使用它在我的解决方案类型。

Now I have access to this image in memory. The thing is I need to convert this to type BitmapImage in order to use it in my solution.

注意:我需要将其转换为键入的BitmapImage 不输入位图。我一直没能因为类型的BitmapImage接受一个开放的为它的构造函数来弄明白。

NOTE: I need to convert it to type BitmapImage not type Bitmap. I haven't been able to figure it out because type BitmapImage takes in a Uri for it's constructor.

推荐答案

从<一个href="http://social.msdn.microsoft.com/forums/en-US/wpf/thread/8327dd31-2db1-4daa-a81c-aff60b63fee6/"相对=nofollow>这个帖子

public BitmapImage ImageFromBuffer(Byte[] bytes)
{
    MemoryStream stream = new MemoryStream(bytes);
    BitmapImage image = new BitmapImage();
    image.BeginInit();
    image.StreamSource = stream;
    image.EndInit();
    return image;
}

这篇关于如何从类型图像转换成键入的BitmapImage?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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