tags:

views:

219

answers:

1

I have a requirement to generate a bitmap containing some characters rendered without anti-aliasing or ClearType.

In Win32-land, I would have created a font with lfQuality set to NONANTIALIASED_QUALITY and drawn with that.

I have tried to do this with WinForms in the following manner:

  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))
    {

But roughFont still seems to render ClearTyped text.

Should I give up with WinForms and just do this in C, or is there something I'm missing here? (My LOGFONT class and associated lfQuality defs come straight from the framework source, so I'm happy they're correct)

A: 

Turns out I was looking the wrong place, and you can't change GDI+ font rendering this way, instead you need to set the TextRenderingHint property on your graphics object, like this:

gr.TextRenderingHint = TextRenderingHint.SingleBitPerPixelGridFit
Will Dean