views:

216

answers:

1

Hello,

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.

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

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

Thanks,

KiTe

+1  A: 

Try something like this:

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;
}
Adel Hazzah