将TextOptions.TextFormattingMode与FormattedText一起使用

dan*_*son 12 wpf c#-4.0

使用WPF4,您可以通过向您的xaml添加TextOptions.TextFormattingMode ="Display"和TextOptions.TextRenderingMode ="Aliased"来获得非模糊文本:

<Window
   TextOptions.TextFormattingMode="Display"
   TextOptions.TextRenderingMode="Aliased">
Run Code Online (Sandbox Code Playgroud)

除了当我使用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));
}
Run Code Online (Sandbox Code Playgroud)

如何使用FormattedText绘制非模糊文本?即我想要使用TextOptions.TextFormattingMode ="Display"和TextOptions.TextRenderingMode ="Aliased".

wil*_*mvn 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));
}
Run Code Online (Sandbox Code Playgroud)

  • 这个答案是对的,为什么有人投票呢? (3认同)

jsc*_*edl 0

按照此处的高级文本格式示例并创建 TextFormatter 对象并使用 TextLine.Draw()