I want to convert a WriteableBitmap
image to a Byte[]
array using C# code in Windows store metro style apps.
WriteableBitmap
exposes PixelBuffer
property of type IBuffer
- a Windows Runtime interface which can be converted to a byte array with .NET Stream
s
byte[] ConvertBitmapToByteArray(WriteableBitmap bitmap)
{
using (Stream stream = bitmap.PixelBuffer.AsStream())
using (MemoryStream memoryStream = new MemoryStream())
{
stream.CopyTo(memoryStream);
return memoryStream.ToArray();
}
}