使用
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”.
解决方法
FormattedText有一个重载的构造函数,允许指定一个TextFormattingMode:
http://msdn.microsoft.com/en-us/library/ee474866.aspx
void DrawText(DrawingContext dc) { FormattedText ft = new FormattedText("Hello World",brush,null,TextFormattingMode.Display); dc.DrawText(ft,rect.Top)); }