0

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();
        }
    }

1 Answer 1

3
public static BitmapImage ByteArraytoBitmap(Byte[] byteArray)
{
    MemoryStream stream = new MemoryStream(byteArray);
    BitmapImage bitmapImage = new BitmapImage();
    bitmapImage.SetSource(stream);
    return bitmapImage;
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot! I did try using streams beforehand, but I used a DataReader instead of a MemoryStream :)
Wich version of framework are you using? I can't found SetSource method in BitmapImage!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.