使用WPF4,您可以通过将TextOptions.TextFormattingMode =“Display”和TextOptions.TextRenderingMode =“Aliased”添加到您的xaml来获得非模糊文本:
<Window
TextOptions.TextFormattingMode="Display"
TextOptions.TextRenderingMode="Aliased">
除了当我使用DrawingContext.DrawText绘制文本时,这对我来说很好用:
void DrawText(DrawingContext dc)
{
FormattedText ft = new FormattedText("Hello World",
System.Globalization.CultureInfo.CurrentCulture,
System.Windows.FlowDirection.LeftToRight,
new Typeface(FontFamily, FontStyle, FontWeight, FontStretch),
FontSize,
brush);
dc.DrawText(ft, new Point(rect.Left, rect.Top));
}
如何使用FormattedText绘制非模糊文本?即我想要使用TextOptions.TextFormattingMode =“Display”和TextOptions.TextRenderingMode =“Aliased”。
答案 0 :(得分:13)
FormattedText
有一个重载的构造函数,允许指定TextFormattingMode
:http://msdn.microsoft.com/en-us/library/ee474866.aspx
void DrawText(DrawingContext dc)
{
FormattedText ft = new FormattedText("Hello World",
System.Globalization.CultureInfo.CurrentCulture,
System.Windows.FlowDirection.LeftToRight,
new Typeface(FontFamily, FontStyle, FontWeight, FontStretch),
FontSize,
brush,
null,
TextFormattingMode.Display);
dc.DrawText(ft, new Point(rect.Left, rect.Top));
}
答案 1 :(得分:0)
按照此处的示例Advanced Text Formatting创建一个TextFormatter对象并使用TextLine.Draw()