字节[]以在Silverlight中的BitmapImage [英] byte[] to BitmapImage in silverlight
本文介绍了字节[]以在Silverlight中的BitmapImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有关游戏的目的,我需要通过WPF应用程序序列化二进制文件的一些图片,采用bitmapEn codeR及其子类。
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.
有人不知道如何一个byte []在Silverlight转换为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屋!
查看全文