原文: WPF字体模糊解决方案

WPF对字体渲染做了很大的改善,与Winform窗体字体相比较,更加平滑,但是当字体大小较小时,则会出现字体模糊的现象。可通过以下方法进行改善处理:

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

对于XAML用户界面,通过对控件添加UseLayoutRounding或者TextOptions的方法

方法一:将TextOptions.TextFormattingMode设置为Display,可以提高字体显示的清晰度

方法二:将UseLayoutRounding设置为Ture,它使得控件布局的时候对齐栅格

<Label Margin="10" VerticalAlignment="Top" Foreground="Black" FontSize="8" Content="示例UseNothing" />
<Label Margin="10" VerticalAlignment="Top" TextOptions.TextFormattingMode="Display" Foreground="Black" FontSize="8" Content="示例TextFormattingMode=Display" />
<Label Margin="10" VerticalAlignment="Top" TextOptions.TextFormattingMode="Ideal" Foreground="Black" FontSize="8" Content="示例TextFormattingMode=Ideal" />
<Label Margin="10" VerticalAlignment="Top" UseLayoutRounding="True" Foreground="Black" FontSize="8" Content="示例UseLayoutRounding=True" />

效果如下:

WPF字体模糊解决方案 随笔 第1张

对于后台通过System.Drawing.Graphics渲染字体,则通过指定文本呈现的质量TextRenderingHint来提高字体清晰度

呈现效果如下:

WPF字体模糊解决方案 随笔 第2张

将TextRenderingHint设置为AntiAliasGridFit效果较好

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄