1
我試圖將RenderTargetBitmap轉換爲字節數組,然後將發送到外部單色OLED屏幕。我知道,位圖正確顯示位/字節對齊應該是LSB到MSB &從上至下:將RenderTargetBitmap轉換爲要在嵌入式屏幕上顯示的字節[]?
但我無法弄清楚如何獲得RenderTargetBitmap的PixelData取出該格式。
目前我已經有了:
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 < rHeight; x++)
{
for (int y = 0; x < 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
將其拷貝到堆棧時,看來你不是在所有使用x和y循環變量,而「索引」變量沒有更新任何地方,總是0 – Evk
我只是刪除了'指數'++錯誤溢出。我修復了它。關於x和y循環,這就是我被阻止的地方。整個部分需要重寫,但我無法弄清楚。 – user2950509