本文介绍了C#上的DrawString文字过于粗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have use GDI DrawString method to draw text. When the program is running, the text on the screen seems very good, however once I saved the files to image, the font will be bolder than before. The normal will be bold, the bold will be much bolder. How to deal with this?

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


推荐答案

我得到了解决方案。

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

Just AntiAlias将解决这个问题。

Just AntiAlias will solve that.

这篇关于C#上的DrawString文字过于粗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 03:29