Rendering issues when drawing text on low-res Magick.Net image

76 Views Asked by At

I'm building a tool which renders text on a low-resolution image (it targets a low-resolution sign).

We're using Magick.NET, so rendering text is quite easy:

using ImageMagick;

MagickImage image = new MagickImage(MagickColors.White, 80, 96);
image.Settings.AntiAlias = false;
image.Settings.StrokeAntiAlias = false;
image.Settings.TextAntiAlias = false;
image.Format = MagickFormat.Png;

var drawables = new Drawables()
            .FillColor(MagickColors.Black)
            .Font("Arial")
            .FontPointSize(14);

drawables.Text(0, 25, "dddDDDddDDWwwWW");
image.Draw(drawables);

image.Write(@"test.png");

But the rendering isn't good - it returns different images for the same letter. Given this example:

enter image description here

As you can see, 'd' is rendered differently on multiple occasions. How can I improve this?

1

There are 1 best solutions below

2
On

You may try to use monospaced font. E.g. in Windows there are builtin 'Consolas' and 'Courier New' monospaced fonts:

var drawables = new Drawables()
        .FillColor(MagickColors.Black)
        .Font("Consolas")
        .FontPointSize(14);

Enabling text antialiasing by TextAntialias(true) should smooth the text:

var drawables = new Drawables()
        .FillColor(MagickColors.Black)
        .Font("Arial")
        .TextAntialias(true)
        .FontPointSize(14);