Render antialiased text using TextRenderer C#
Asked Answered
A

1

0

I wrote a program to draw some string on an image. I use graphics.DrawString() but as you can see in this post, it has some problems.
TextRenderer.DrawText() solved that problem but the rendered text is jagged. I changed both graphics.TextRenderingHint and resolution of graphics; TextRenderer doesn't care at all.
There should be a solution as it is done here; but I don't know how to do it.

Ac answered 21/9, 2020 at 7:11 Comment(3)
Reading second link, looks like you have to set font quality manually? Graphics object properties (GDI+) do not affect Textrenderer (GDI) - or that is how I understand linked information.Signpost
@Signpost How should I set font quality?Ac
I have no idea, this is just what I understood from linked discussion.Signpost
I
0
        private void panel1_Paint(object sender, PaintEventArgs e)
        {
            //GDI (i.e. TextRenderer)
            String s = "The quick brown fox jumped over the lazy dog";
            Point origin = new Point(11, 11);
            Font font = SystemFonts.IconTitleFont;

            e.Graphics.TextRenderingHint = TextRenderingHint.SingleBitPerPixel;

            TextRenderer.DrawText(e.Graphics, s, font, origin, SystemColors.InfoText);
        }

Full demo showing that it does work: https://mega.nz/file/E3xREYIR#kuDxyac_0jxlX7wuTVmZmJgClEicdaCj0YpnE83Wq9k

Immolate answered 23/9, 2020 at 18:53 Comment(1)
You're right. However effect of these properties are really low on this font (IranNastaliq). I couldn't detect the difference between different TextRenderingHint modes for TextRenderer at first. Only a few (maybe less than 10) pixels are different between all modes. Also, when I increase font size, the overlapping problem appears again even using TextRenderer.Ac

© 2022 - 2024 — McMap. All rights reserved.