You can use this simple code to understand how convert stream to byte[].
public static byte[] ToByteArray(this WriteableBitmap bmp)
{
int w = bmp.PixelWidth;
int h = bmp.PixelHeight;
int[] p = bmp.Pixels;
int len = p.Length;
byte[] result = new byte[4 * w * h];
for (int i = 0, j = 0; i < len; i++, j += 4)
{
int color = p[i];
result[j + 0] = (byte)(color >> 24);
result[j + 1] = (byte)(color >> 16);
result[j + 2] = (byte)(color >> 8);
result[j + 3] = (byte)(color);
}
return result;
}