wpf 加阴影效果导致内容模糊的问题解决

时间:2022-04-12 22:47:08
wpf 加阴影效果导致内容模糊的问题解决

这个和GPU有关,参考地址

https://www.cplotts.com/2009/02/25/gpu-effects-blurry-text/

产生问题的代码如下:

 <Window
x:Class="EffectsAndBlurryText.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Effects and Blurry Text (Bad)"
Height="300"
Width="500"
>
<Grid>
<Border
Margin="20"
Background="White"
BorderBrush="DarkBlue"
BorderThickness="3"
CornerRadius="25"
>
<Border.Effect>
<DropShadowEffect Color="DarkGray"/>
</Border.Effect>
<TextBlock
Text="Why, oh, why is this text blurry?"
FontSize="24"
TextWrapping="Wrap"
Foreground="DarkBlue"
HorizontalAlignment="Center"
VerticalAlignment="Center"
/>
</Border>
</Grid>
</Window>

解决问题的代码如下:

 <Window
x:Class="EffectsAndBlurryText.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Effects and Blurry Text (Fixed)"
Height="300"
Width="500"
>
<Grid>
<Border
Margin="20"
BorderThickness="3"
CornerRadius="25"
Background="White"
BorderBrush="DarkBlue"
>
<Border.Effect>
<DropShadowEffect Color="DarkGray"/>
</Border.Effect>
</Border>
<Border
Margin="20"
BorderThickness="3"
CornerRadius="25"
>
<TextBlock
Text="Ah, now, the text is not blurry."
FontSize="24"
TextWrapping="Wrap"
Foreground="DarkBlue"
HorizontalAlignment="Center"
VerticalAlignment="Center"
/>
</Border>
</Grid>
</Window>