Rob
Rob

Reputation: 3381

How to create anti-aliased text on a Bitmap with ExtTextOut?

In my WinForm app I draw into a System.Drawing.Bitmap. I create fonts from a LOGFONT and draw using the GDI function ExtTextOutW. However the output is terrible. It has bad jaggies and looks like the antialiaser was on LSD. Reading around this seems a common issue - is there a resolution?

If I use:

lf.lfQuality = FontQuality.NONANTIALIASED_QUALITY

when I create the font then the horrible jaggies go away but of course there is no antialiasing.

Is there a way to create smooth text in a Bitmap with ExtTextOutW?

Upvotes: 1

Views: 961

Answers (1)

Arthur
Arthur

Reputation: 1548

It is possible but a bit tricky and it can't have transparent background. You will need to:

  1. Create in-memory bitmap buffer that is compatible with display device context (IntPtr.Zero handle)
  2. Fill the buffer background with solid color or other background
  3. Render the text into the memory bitmap
  4. Copy from in-memory bitmap to image device context (BitBlt)

See GDI text rendering to image for more details.

Upvotes: 1

Related Questions