字节 [] 到 Silverlight 中的 BitmapImage [英] byte[] to BitmapImage in silverlight

查看:28
本文介绍了字节 [] 到 Silverlight 中的 BitmapImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于游戏目的,我需要通过 WPF 应用程序使用 bitmapEncoder 及其子类将二进制文件中的一些图片序列化.

For the purpose of a game, I need to serialize some pictures in a binary file through a WPF application, using bitmapEncoder and its child classes.

但是这些类在 Silverlight 中不可用,所以我无法将它们从同一个二进制文件加载到浏览器中.

But these class are not available in silverlight, so I can't load them into the browser from the same binary file.

有人知道如何在silverlight中将byte[]转换为BitmapImage吗?

Does someone know how to convert a byte[] to BitmapImage in silverlight?

谢谢,

风筝

推荐答案

试试这个:

BitmapImage GetImage( byte[] rawImageBytes )
{
    BitmapImage imageSource = null;

    try
    {
        using ( MemoryStream stream = new MemoryStream( rawImageBytes  ) )
        {
            stream.Seek( 0, SeekOrigin.Begin );
            BitmapImage b = new BitmapImage();
            b.SetSource( stream );
            imageSource = b;
        }
    }
    catch ( System.Exception ex )
    {
    }

    return imageSource;
}

这篇关于字节 [] 到 Silverlight 中的 BitmapImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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