System.Drawing - bad text rendering using DrawString on top of transparent pixels.
Posted
by mackenir
on Stack Overflow
See other posts from Stack Overflow
or by mackenir
Published on 2010-06-07T16:56:10Z
Indexed on
2010/06/07
17:22 UTC
Read the original article
Hit count: 305
When rendering text into a bitmap, I find that text looks very bad when rendered on top of an area with non-opaque alpha. The problem is progressively worse as the underlying pixels become more transparent. If I had to guess I'd say that when underlying pixels are transparent, the text renderer draws any anti-aliased 'gray' pixels as solid black.
Here are some screenshots:
Text drawn on top of transparent pixels:
Text drawn on top of semi-transparent pixels:
Text drawn on opaque pixels:
Here is the code used to render the text:
g.SmoothingMode = SmoothingMode.HighQuality;
g.DrawString("Press the spacebar", Font, Brushes.Black, textLeft, textTop);
© Stack Overflow or respective owner