WPF4文字模糊不清晰、边框线条粗细不一致的解决方法

软件测试过程中发现在一台1600*900的分辨率电脑上文字模糊,甚至某些个文字出现压缩扭曲

经过实践,发现按下面方法能解决一点问题:

在窗口或控件上设置字体属性就可以了(红色标注部分),如下:

<UserControl x:Class="..."
             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" TextOptions.TextRenderingMode="ClearType" TextOptions.TextHintingMode="Fixed" UseLayoutRounding="True">

注:TextOptions.TextHintingMode="Fixed"  UseLayoutRounding="True"  必须加在窗口或控件上,否则写在样式里无效

主要属性的意义:

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.UseLayoutRounding

获取或设置一个值,该值确定对象及其可视化子树的呈现是否应使用将呈现与整像素对齐的舍入行为。UserLayoutRounding为False,导致控件布局相对屏幕若不是整数则不会四舍五入,导致边缘模糊。

最后:如果把‘宋体’、‘黑体’、‘微软雅黑’这类字体设置成Times New Roman等英文字体,清晰度倒是明显提升了。(亲测有效)

原文地址:https://www.cnblogs.com/softwyy/p/9717567.html

时间: 2024-07-31 09:01:46

WPF4文字模糊不清晰、边框线条粗细不一致的解决方法的相关文章

wpf4 文字 模糊 不清晰 解决方法

在窗口或控件上设置字体属性就可以了,如下: <UserControl x:Class="..." xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/mar

表格线边框重复css解决方法

1.td 的边框和table 的边框重叠 .table { border-left:1px solid #dedede; border-top:1px solid #dedede;} .td { border-right:1px solid #dedede; border-bottom:1px solid #dedede;} table 只用左边框和上边框,每个td只有右边框和下边框,效果就是整个表格左.上边框是连续实线,右.下边框是延续td的边框所以是断断续续的 解决方法: .table {b

input,button制作按钮IE6,IE7点击时1px黑边框的解决方法

按钮在IE6中点击时1px黑边框的最常见的解决方法 首先设置按钮为none,然后在按钮外面套一层来实现边框的效果,部分代码如下 .btnbox{ border:solid 1px red;} .btn{ border:none;} <span class="btnbox"><input class="btn" type="button" value="按钮"></span> 第二种办法通过滤

CSS3动画:流彩文字效果+图片模糊效果+边框伸展效果实现

前言 首先第一步,先布局html代码如下: <div class="wrap"> <img src="images/1.jpg" class="blur"/> <div class="text-gradient ">天赐神功</div> <div class="border"></div> </div> 上面一看第一个图片i

js+css3文字模糊代码

在写文字模糊的时候要理清自己的思路,根据以下的步骤来: 对你要模糊的文字进行布局 <body style="background:#ccc;"> <ul class="con"> <li><h2>我是box1</h2></li> <li><h2>我是box2</h2></li> <li><h2>我是box3</h2&g

echarts设置线条粗细

series: [ { name:"buy", type:'line', data:[], itemStyle: { normal: { color: '#6cb041', lineStyle:{ width:3//设置线条粗细 } } } } ] 可查看资料:http://echarts.baidu.com/echarts2/doc/example/themeDesigner.html

高光导航、文字模糊

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <ti

绘制线条粗细 以及 绘制变化的坐标

  <!DOCTYPE html>   <html>   <head lang="en">   <meta charset="UTF-8">   <title></title>   </head>   <body>   <canvas id="mycas" width="400" height="400"&

cocos2dx3.x 文字模糊解决方法

cocos2dx 真是要命啊,由于公司要做跨平台游戏,故在windows里面cocos2dx 经常抽风. 没办法啊,本来不想改源码的,且改且珍惜啊. 最近又遇到了在windows下面文字模糊的情况,由于字体绘制跟图片绘制如出一辙,故断定一定是字体没有开启抗锯齿功能. 因此只能单步调试: 找到了字体初始化入口:Texture2D::initWithString bool Texture2D::initWithString(const char *text, const FontDefinition