字体非常难看

时间:2011-01-18 12:00:46

标签: c# .net asp.net graphics fonts

我正在使用以下代码绘制一个字符串:

public Image DrawString(String lString)
{
    Image lImage = new Bitmap(128, 128);
    Rectangle rec = new Rectangle(0, 0, lImage.Width, lImage.Height);

    Graphics g = Graphics.FromImage(lImage);
    g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;

    drawFormat = new StringFormat();
    drawFormat.Alignment = StringAlignment.Center;
    drawFormat.LineAlignment = StringAlignment.Center;

    Font font = new Font("Arial", 20, FontStyle.Regular);
    font = FindBestFitFont(g, lString, font, rec.Size); 
    g.DrawString(lString, font, Brushes.Red, rec, drawFormat);

    return lImage;
}

即使我使用字体,字体看起来也很难看:

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

有没有办法让字体更流畅?

2 个答案:

答案 0 :(得分:7)

尝试

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

代替。

答案 1 :(得分:1)

您是否尝试过AntiAliasing或ClearType?

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