WPF 4文字模糊不清晰解决方法

来源:互联网 发布:js window.setinterval 编辑:程序博客网 时间:2024/05/02 00:10

在窗口或控件上设置字体属性就可以了,如下:

<usercontrol p="" <="" x:class="OPClient.PlatformManage.UserControlProxy">

以下是代码片段:
<UserControl x:Class="OPClient.PlatformManage.UserControlProxy" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
mc:Ignorable="d" 
d:DesignHeight="400" d:DesignWidth="800" 
FontFamily="NSimSun" FontSize="14" TextOptions.TextFormattingMode="Display">

  参考:

  WPF4字体改善

  WPF4对字体渲染做了很大的改善,增加了TextOptions属性,该属性可以设置TextFormattingMode,TextRenderingMode,TextHintingMode

  1.TextFormattingMode

  它提供了两种设置:

  · Ideal —— WPF4之前的模式

  · Display —— 新的模式,可以使字体显示更清晰

  (一般将TextFormattingMode设置为Display,可以提高字体显示的清晰度)

  2.TextRenderingMode

  设置渲染模式,可以有以下设置:

  Auto – This mode will use ClearType unless system settings have been set to specifically disable ClearType on the machine.

  Aliased – No antialiasing will be used to draw text.

  Grayscale – Grayscale antialiasing will be used to draw text.

  ClearType – ClearType antialising will be used to draw text.

  (一般用ClearType渲染出来的字体会比较平滑)

  3.TextHintingMode

  获取或设置一个值,该值影响文本元素的呈现行为,这是一种性能优化方式,当您对文本元素的任何文本属性进行动画处理时,可以使用此方式。

  此属性的值采用以下两种可能的值:

  Animated 通过使用一个更高效、但视觉精确下降的平滑算法来针对动画进行优化。(文本仍然是可读的;精度损失并不严重。)

  Fixed(默认值)使用的算法针对视觉上精确的字体平滑效果进行了优化,但当将动画应用于字体元素的属性时,可能导致性能问题以及抖动,尤其是对于 FontSize 或转换/定位/投影。

  (在需要对字体做一些动态效果,例如将字体缩放时,使用Animated能获取较高的性能,但同时也影响了其显示的清晰度)

  4.WPF4.0中同时针对东亚字体的渲染进行了优化,现在它支持点阵字体了,而开启这个新特性十分简单,只需为FontFamily设置一种点阵字体就可以了