TinyCLR 2.0 System.Drawing.Font Error

I ran this simple code on a FEZ Feather running TinyCLR 2.0.0 and I am getting an error calling the DrawString method.

Error:
An unhandled exception of type ‘System.ArgumentException’ occurred in GHIElectronics.TinyCLR.Drawing.dll

static void Main()
        {
            var controller = I2cController.FromName(SC20100.I2cBus.I2c1);
            var i2cDevice = controller.GetDevice(SSD1306Controller.GetConnectionSettings());
            SSD1306Controller ssd1306Controller = new SSD1306Controller(i2cDevice);
            
            var screen = Graphics.FromImage(new Bitmap(128, 32));
            var font = new Font("GHIMono8x5", 8);
            var brush =  new SolidBrush(System.Drawing.Color.White);
            Graphics.OnFlushEvent += (s, d) => {
                ssd1306Controller.DrawBuffer(d);
            };
            screen.FillRectangle(brush, 0, 0, 30, 32); //Works
            screen.Flush();

            screen.DrawEllipse(new System.Drawing.Pen(System.Drawing.Color.White), 32, 0, 30, 30); //Works
            screen.Flush();
            Thread.Sleep(1000);
            screen.DrawString("Welcome", font, brush, 34, 0); //Throws an error
            screen.Flush();

            Thread.Sleep(Timeout.Infinite);
        }

Doing some investigation, I noticed that the height property on the Font class is throwing an error.
image

Is this the proper way to instantiate the font class?

var font = new Font("GHIMono8x5", 8);

that font is no longer supported.

Thanks Dat.

So is there another built-in font or do I have to convert a font using the font conversion tool?

you need to convert.

This is no longer supported. Where did you find this code?

Thanks again.

Hey Gus,

https://docs.ghielectronics.com/software/tinyclr/tutorials/font-support.html

Built-in fonts

When using systems with managed SPI display drivers, the font support is handled though an internal built-in font. This is done to reduce memory requirements.

var teal = new SolidBrush(Color.Teal);
var font = new Font("GHIMono8x5", 8);
screen.DrawString("Hello World!", font, teal, 40, 10);
screen.Flush();

Thanks,

Added an issue :))

https://github.com/ghi-electronics/TinyCLR-Devices/issues/827

1 Like