我需要生成一个包含一些没有消除锯齿或ClearType的字符的位图。
在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直接来自框架源,所以我很高兴他们是正确的)
答案 0 :(得分:1)
原来我看错了地方,你不能用这种方式改变GDI +字体渲染,而是需要在你的图形对象上设置TextRenderingHint属性,如下所示:
gr.TextRenderingHint = TextRenderingHint.SingleBitPerPixelGridFit
答案 1 :(得分:0)
我知道这不是关于位图,但我一直在为我的问题寻找解决方案,并推出了这个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);
}
}
也许有人会发现它很有用