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
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With