C#上的DrawString文字过于粗体

时间:2014-07-15 01:46:10

标签: c# image gdi+ drawstring

我使用GDI DrawString方法绘制文字。当程序运行时,屏幕上的文字似乎非常好,但是一旦我将文件保存到图像,字体将比以前更大胆。正常将是大胆的,大胆将更大胆。怎么处理这个?

public override void DrawTo(Graphics g, int x, int y, int flag)
    {
        if (flag == 1)
        {
            Pen dpen = new Pen(Color.FromArgb(128, 0, 0, 0), 1);
            dpen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot;
            g.DrawRectangle(dpen, new Rectangle(Bounds.X + x, Bounds.Y + y, Bounds.Width, Bounds.Height));
        }

        if (!string.IsNullOrEmpty(Text))
        {

            g.DrawString(Text, Font, new SolidBrush(Color), new Rectangle(Bounds.X + x, Bounds.Y + y, Bounds.Width, Bounds.Height));
        }
    }

2 个答案:

答案 0 :(得分:4)

我得到了解决方案。

g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

Just AntiAlias将解决这个问题。

答案 1 :(得分:0)

我有同样的问题。 我尝试使用TextRenderingHint,SmoothingMode,TextContrast,但是它什么也没改变。

我已将graph.Clear(Color.Transparency)替换为graph.Clear(Color.White),并且Text现在看起来不错。

相关问题