How to convert a WriteableBitmap image to an array of bytes in a WinRt application

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

+6
source share
1 answer

WriteableBitmap provides a PixelBuffer property of type IBuffer , a Windows Runtime interface that 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(); } } 
+8
source

Source: https://habr.com/ru/post/943505/


All Articles