本文介绍了使用TextRenderer C#渲染抗锯齿的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个程序在图像上绘制一些字符串.我使用graphics.DrawString(),但正如您在帖子中看到的那样,它存在一些问题.
TextRenderer.DrawText()解决了该问题,但渲染的文本呈锯齿状.我同时更改了graphics.TextRenderingHint和图形的分辨率; TextRenderer根本不在乎.
此处,应该有一个解决方案.但我不知道该怎么做.

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.

推荐答案

        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);
        }

完整的演示表明它可以起作用: https://mega. nz/file/E3xREYIR#kuDxyac_0jxlX7wuTVmZmJgClEicdaCj0YpnE83Wq9k

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

这篇关于使用TextRenderer C#渲染抗锯齿的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 12:47