Convert a RenderTargetBitmap to a byte[] to be displayed on a embedded screen?
<p>I'm trying to convert a RenderTargetBitmap to a byte array that will then get sent off to an external monochrome OLED screen. I know that for the bitmap to display correctly the bit/byte alignment should be LSB to MSB &amp; Top to Bottom:</p>

<p><a href="https://i.stack.imgur.com/XB19j.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XB19j.png" alt="enter image description here"></a></p>

<p>But I can't figure out how to get the RenderTargetBitmap's pixeldata in that format.</p>

<p>For the moment I've got:</p>

<pre><code>        RenderTargetBitmap renderTargetBitmap; //This is already set higher up
        DataReader reader = DataReader.FromBuffer(await renderTargetBitmap.GetPixelsAsync());

        // Placeholder for reading pixels
        byte[] pixel = new byte[4]; // RGBA8

        // Write out pixels
        int index = 0;
        byte[] array = new byte[renderTargetBitmap.PixelWidth*renderTargetBitmap.PixelHeight];
        using (reader)
        {
            //THIS IS WHERE I THINK I'M SCREWING UP
            for (int x = 0; x &lt; rHeight; x++)
            {
                for (int y = 0; x &lt; rWidth; y++)
                {
                    reader.ReadBytes(pixel);
                    if (pixel[2] == 255)
                        array[index] = 0xff;
                    else
                        array[index] = 0x00;
                    index++;
                }
            }
        }
        sh1106.ShowBitmap(buffer); //Send off the byte array
</code></pre>