用WinForms生成非反锯齿字体

问题描述:

我有一个要求,生成一个包含一些字符呈现没有反锯齿或ClearType的位图。用WinForms生成非反锯齿字体

在Win32-land中,我会创建一个lfQuality设置为NONANTIALIASED_QUALITY的字体并用它来绘制。

我曾尝试用以下方式的WinForms要做到这一点:

using(Font smoothFont = new Font("Arial", 30, GraphicsUnit.Pixel)) 
    { 
    LOGFONT lf = new LOGFONT(); 
    smoothFontToLogFont(lf); 
    lf.lfQuality = NONANTIALIASED_QUALITY; 
    using (Font roughFont = Font.FromLogFont(lf)) 
    { 

但roughFont似乎仍然呈现ClearTyped文本。

我应该放弃WinForms,只是在C中做这件事,或者有什么我在这里失踪? (我的LOGFONT类和相关的lfQuality defs直接来自框架源,所以我很高兴他们是正确的)

原来我看错了地方,而且你不能用这种方式更改GDI +字体渲染,相反,你需要设置TextRenderingHint财产上的图形对象,像这样:

gr.TextRenderingHint = TextRenderingHint.SingleBitPerPixelGridFit 
+0

谢谢!这个解决方案为我节省了很多麻烦。我以前超级模糊的字体现在看起来很棒:) – ChandlerPelhams 2011-11-22 01:27:20

我知道这是不是位图,但我一直在寻找我的问题的解决方案以及与此LabelEx出来修饰

using System.Drawing; 
using System.Drawing.Text; 

class LabelEx : System.Windows.Forms.Label 
{ 
    protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) 
    { 
     e.Graphics.TextRenderingHint = TextRenderingHint.SingleBitPerPixelGridFit; 
     base.OnPaint(e); 
    } 
} 

也许有人会发现我t很有用