Monday, January 26, 2015

Convert BitmapImage to byte[]

Hi!


In windows store apps BitmapImage does not have a StreamSource property. You can achieve what you want like this:



using System.Runtime.InteropServices.WindowsRuntime;

...

byte[] buffer = null;

using (MemoryStream ms = new MemoryStream())
{
WriteableBitmap wb = new WriteableBitmap(imageSource);
Stream s1 = wb.PixelBuffer.AsStream();
s1.CopyTo(ms);

buffer = ms.ToArray();
}


Cheers,


Sam.


No comments:

Post a Comment