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.
Render antialiased text using TextRenderer C#
Asked Answered
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
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
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.