Convert BitmapImage to byte[] array in Windows Phone 8.1 Runtime

前端 未结 2 443
借酒劲吻你
借酒劲吻你 2021-01-20 13:16

There are a few samples to do this but they are for Windows Phone 8.0 or 8.1 Silverlight.

But how can you do this for Windows Phone 8.1 Runtime?

2条回答
  •  不要未来只要你来
    2021-01-20 14:01

    Tried this?

    private byte[] ConvertToBytes(BitmapImage bitmapImage)
    {
        byte[] data = null;
        using (MemoryStream stream = new MemoryStream())
        {
            WriteableBitmap wBitmap = new WriteableBitmap(bitmapImage);
            wBitmap.SaveJpeg(stream, wBitmap.PixelWidth, wBitmap.PixelHeight, 0, 100);
            stream.Seek(0, SeekOrigin.Begin);
            data = stream.GetBuffer();
        }
    
        return data;
    }
    

提交回复
热议问题