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.

AmirSina Mashayekh
  • 498
  • 1
  • 5
  • 21

1 Answers1

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

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
  • 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](https://stackoverflow.com/q/63816737/10600811) appears again even using `TextRenderer`. – AmirSina Mashayekh Sep 24 '20 at 08:11