Main Site Documentation

N18 bitmaps in .NetMF


#1

I’m trying to draw bitmaps to the Display N18 from a STM32F405RGT6 (I think that’s similar to the one on the FEZ Cerberus) running NetMF 4.2

When I try to follow the instructions for drawing a bitmap fragment to the N18 display at https://www.ghielectronics.com/docs/59/display-n18-module I’m not sure what bit depth to use. The instructions recommend using Paint, which saves bitmaps by default at 24 bit but later in the code the byte array size calculation (byte[] newRender = new byte[128 * 160 * 2]:wink: makes me think it should be 16bit. What is the bit depth the N18 expects?

When I run the sample code I get an error.

var tdata = Resources.GetBytes(Resources.BinaryResources.yes_no);
var picture = new Bitmap(tdata, Bitmap.BitmapImageType.Bmp);
var newRender = new byte[13*79*2];
Array.Copy(newRender, picture.GetBitmap(), newRender.Length);
_display.DrawRaw(newRender, 13, 79, 50, 50);

The second line throws the error:

An unhandled exception of type ‘System.NotSupportedException’ occurred in Microsoft.SPOT.Graphics.dll

Why do I get this error and how should I fix it?


#2

it’s 16 bit for sure.
NETMF Bitmaps are always 16 bit.
But I’m actually not sure what format.
I think that’s something the driver for N18 configures in the display.


#3

Taylorza to the rescue…

https://www.ghielectronics.com/community/codeshare/entry/744


#4

Thanks Reinhard & Bill.

In the usage code, where does the class Display_N18.TinyBitmap in the line



come from? I don't seem to have it.

#5

@ dumbledad - Sometime after that code was written GHI dropped the TinyBitmap from their interface and added support for handling standard .NETMF Bitmaps. However, using TinyBitmapConverter will still work for you.

To use DrawRaw, you should not be using the bytes you get from Bitmap.GetBitmap(), you need to have a raw byte buffer with just the pixel data, Bitmap.GetBitmap() includes bitmapinfoheader data etc.

Using TinyBitmapConverter you can convert a bmp to the raw byte 16bit representation and then add that file as a resource to your application. Once you have that, you can use the following code to render the bitmap.


var tdata = Resources.GetBytes(Resources.BinaryResources.yes_no);
_display.DrawRaw(tdata, 13, 79, 50, 50);

Where Resources.BinaryResources.yes_no is the raw data and not the original bitmap.