I have WriteableBitmap. I know that in variable wp1 exists image, because I saved this picture, and it was all fine. I need to encode the image into a byte[] array.
WriteableBitmap wp1 = new WriteableBitmap(1, 1); ;
wp1.SetSourceAsync(memStream);
using (Stream stream = wp1.PixelBuffer.AsStream())
{
if (stream.CanWrite)
{
byte[] pixelArray = new byte[stream.Length];
await stream.ReadAsync(pixelArray, 0, pixelArray.Length);
}
}
After all the pixelArray is empty. Length of the array pixelArray equals to the length of stream, but all bytes are zero. What should I do?
SetSourceAsyncisn't what you want - and I notice you're not awaiting it, either.