使用WPF4,可以通过在您的xaml中添加TextOptions.TextFormattingMode =“Display”和TextOptions.TextRenderingMode =“Aliased”来获得非模糊文本:
<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",
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));
}
关于wpf - 将TextOptions.TextFormattingMode与FormattedText一起使用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2550632/