Hi,
I wrote a small, basic driver for an ePaper-display (so 1bit bitmaps are used). I draw the screen into a Bitmap, then convert it to a 1bit-Bitmap (since I couldn’t find a way to create 1bit-Bitmaps), so send it to my display via SPI. The problem is, I think the
returns another Bitmap-layout, than my display wants to have. My display wants a stream of bytes in one line (I don't know how to describe it properly :D)
I want it that way:
```cs
7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 ......
......
But I think the returned pattern is:
7 7 7 7 7 7 7 7 ......
6 6 6 6 6 6 6 6 ......
5 5 5 5 5 5 5 5 ......
4 4 4 4 4 4 4 4 ......
3 3 3 3 3 3 3 3 ......
2 2 2 2 2 2 2 2 ......
1 1 1 1 1 1 1 1 ......
0 0 0 0 0 0 0 0 ......
......
So I wrote a helper-method, that reads the bitmap pixel-by-pixel and creates a fitting array, but thats horribly slow on my G120 (about 350ms for one 112x208px bitmap, using a LargeBuffer instead of a byte[] it even takes ~650ms), the GHI…Convert()-Methos takes only 14ms…
private static byte[] ImageConverter(Bitmap BMP)
{
int HORCNT = 0;
int VERCNT = 0;
int IMAGEHEIGHT = BMP.Height;
int IMAGEWIDTH = BMP.Width;
int ARRAYSIZE = (IMAGEWIDTH * IMAGEHEIGHT) / 8;
byte[] DisplayBuffer = new byte[ARRAYSIZE];
for (int cnt = 0; cnt < ARRAYSIZE; cnt++)
{
DisplayBuffer[cnt] = 0;
for (int i = 0; i <= 7; i++)
{
if (BMP.GetPixel(HORCNT, VERCNT) != Microsoft.SPOT.Presentation.Media.Colors.Black)
{
if (i == 7) DisplayBuffer[cnt] += 1;
if (i == 6) DisplayBuffer[cnt] += 2;
if (i == 5) DisplayBuffer[cnt] += 4;
if (i == 4) DisplayBuffer[cnt] += 8;
if (i == 3) DisplayBuffer[cnt] += 16;
if (i == 2) DisplayBuffer[cnt] += 32;
if (i == 1) DisplayBuffer[cnt] += 64;
if (i == 0) DisplayBuffer[cnt] += 128;
}
HORCNT += 1;
}
if (HORCNT == IMAGEWIDTH)
{
VERCNT += 1;
HORCNT = 0;
//Debug.Print("Byte# " + cnt);
}
}
return DisplayBuffer;
}
So is there an simple way to convert the bitmap-layouts?
I added two images, one is the bitmap the GHI…Convert()-Method creates, the other is the one, my very slow Method creates…
I’m almost sure, the professional-coders here can solve this with one line of code :wall: :think: :-[