简体   繁体   中英

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();
        }
    }
public static BitmapImage ByteArraytoBitmap(Byte[] byteArray)
{
    MemoryStream stream = new MemoryStream(byteArray);
    BitmapImage bitmapImage = new BitmapImage();
    bitmapImage.SetSource(stream);
    return bitmapImage;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM