user1123530
user1123530

Reputation: 561

Byte array to BitmapImage WP

I'm trying to get BitmapImage serialization working on Windows Phone 8, but it seems that a lot of libraries are missing from the WP SDK compared to desktop C# apps...

Basically I've got a Byte array that I need to parse into a BitmapImage for displaying, however nothing I could find on the web works... Any help is much appreciated! :)

Since StackOverflow's algorithm thinks this question is too trivial, I'm just gonna paste the code that I've got working to convert the BitmapImage to a ByteArray

public static Byte[] ImageToByteArray(BitmapImage image)
    {
        using (MemoryStream ms = new MemoryStream())
        {
            WriteableBitmap btmMap = new WriteableBitmap
                (image.PixelWidth, image.PixelHeight);

            Extensions.SaveJpeg(btmMap, ms,
                image.PixelWidth, image.PixelHeight, 0, 100);

            return ms.ToArray();
        }
    }

Upvotes: 0

Views: 2638

Answers (1)

anderZubi
anderZubi

Reputation: 6424

public static BitmapImage ByteArraytoBitmap(Byte[] byteArray)
{
    MemoryStream stream = new MemoryStream(byteArray);
    BitmapImage bitmapImage = new BitmapImage();
    bitmapImage.SetSource(stream);
    return bitmapImage;
}

Upvotes: 3

Related Questions