Let's suppose we have to draw a bitmap with a piece of text in C# using System.Drawing. The text characters will not look very good and smooth by default. Enabling ClearType in windows would have solved a problem but suppose we want to change nothing in windows.
It can be a web server generating string bitmaps, so enabling ClearType would be counter-productive and take unnecessary resources from unrelated processes. Not to mention — the end user will see the lowest text quality despite ClearType settings on her computer because the bitmap is generated on the server with ClearType disabled.
Implementing Graphics.TextRenderingHint property which specifies the quality of text rendering would solve the problem. Graphics.TextRenderingHint utilizes one value from TextRenderingHint enumeration for example ClearTypeGridFit (which means — use ClearType). Example:
grph.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; grph.DrawString(myString, myFont, myBrush, xPosition, yPosition);
TextRenderingHint enumeration values range from SystemDefault (fastest performance, but lowest quality) to ClearTypeGridFit (best quality).
Friday, March 13, 2009 2:39 PM