How to Convert a WriteableBitmap image to Byte arr

2019-02-09 20:25发布

I want to convert a WriteableBitmap image to a Byte[] array using C# code in Windows store metro style apps.

1条回答
迷人小祖宗
2楼-- · 2019-02-09 21:00

WriteableBitmap exposes PixelBuffer property of type IBuffer - a Windows Runtime interface which can be converted to a byte array with .NET Streams

    byte[] ConvertBitmapToByteArray(WriteableBitmap bitmap)
    {
        using (Stream stream = bitmap.PixelBuffer.AsStream())
        using (MemoryStream memoryStream = new MemoryStream())
        {
            stream.CopyTo(memoryStream);
            return memoryStream.ToArray();
        }
    }
查看更多
登录 后发表回答