How to Convert a WriteableBitmap image to Byte array in WinRt App

后端 未结 1 494
青春惊慌失措
青春惊慌失措 2021-01-02 23:00

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

相关标签:
1条回答
  • 2021-01-02 23:48

    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();
            }
        }
    
    0 讨论(0)
提交回复
热议问题