加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

wpf – 使用具有FormattedText的TextOptions.TextFormattingMode

发布时间:2020-12-15 06:45:03 所属栏目:百科 来源:网络整理
导读:使用 WPF4,您可以通过将TextOptions.TextFormattingMode =“Display”和TextOptions.TextRenderingMode =“Aliased”添加到xaml中,可以具有非模糊的文本: Window TextOptions.TextFormattingMode="Display" TextOptions.TextRenderingMode="Aliased" 这对我
使用 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));
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读