如何转换WriteableBitmap的图像字节数组中的WinRT应用(How to Convert

2019-09-01 00:05发布

我想一个转换WriteableBitmap图像以一个Byte[]使用C#代码在Windows应用商店的Metro风格应用阵列。

Answer 1:

WriteableBitmap暴露PixelBuffer类型的属性IBuffer -一个Windows运行时接口,其可以被转换为一个字节数组与.NET Stream小号

    byte[] ConvertBitmapToByteArray(WriteableBitmap bitmap)
    {
        using (Stream stream = bitmap.PixelBuffer.AsStream())
        using (MemoryStream memoryStream = new MemoryStream())
        {
            stream.CopyTo(memoryStream);
            return memoryStream.ToArray();
        }
    }


文章来源: How to Convert a WriteableBitmap image to Byte array in WinRt App