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;
}
2
  • Thanks a lot! I did try using streams beforehand, but I used a DataReader instead of a MemoryStream :) Jul 20, 2013 at 14:01
  • Wich version of framework are you using? I can't found SetSource method in BitmapImage!
    – arturn
    Feb 27, 2017 at 12:27

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.