WPF陰影、模糊

原文  http://blog.csdn.net/a771948524/article/details/9259557html

 

1.首先最多見的一個陰影效果的類是DropShadowEffect。它有幾種比較有用的屬性好比:Color設置顏色,Direction設置投影的方向,ShadowDepth設置投影距紋理下方的距離,Opacity設置透明度等等。角度的設置是這樣的:windows

下面是一個例子和效果:ui

[html]  view plain copy
 
  1. <TextBlock Text="HELLO WORLD" Foreground="Green" HorizontalAlignment="Center" Margin="20" FontSize="36">  
  2.             <TextBlock.Effect>  
  3.                 <DropShadowEffect Color="Black" Direction="0" ShadowDepth="5" Opacity="1" />  
  4.             </TextBlock.Effect>  
  5.         </TextBlock>  


2.接下來是模糊效果的類BlurEffect。能夠設置Radius模糊效果曲線的半徑,KernelType計算模糊的曲線的值等等。spa

[html]  view plain copy
 
  1. <TextBlock Text="Hello world" Foreground="Green" HorizontalAlignment="Center" Margin="20" FontSize="36">  
  2.             <TextBlock.Effect>  
  3.                 <BlurEffect Radius="4" KernelType="Box" />  
  4.             </TextBlock.Effect>  
  5.         </TextBlock>  

 

3.好吧貌似沒撒能用的了,不過還能夠用TranslateTransform來疊兩個一樣的東西來顯示弄出陰影效果。.net

[html]  view plain copy
 
  1. <Grid>  
  2.     <TextBlock Text="helloworld" Foreground="Black" HorizontalAlignment="Center" Margin="20" FontSize="36">  
  3.             <TextBlock.RenderTransform>  
  4.                 <TranslateTransform X="3" Y="3" />  
  5.             </TextBlock.RenderTransform>  
  6.     </TextBlock>  
  7.     <TextBlock Text="helloworld" Foreground="Green" HorizontalAlignment="Center" Margin="20" FontSize="36" />  
  8.   
  9. </Grid>  

4.最後弄張相框類型的陰影圖片來玩玩。orm

[html]  view plain copy
 
    1. <Border SnapsToDevicePixels="True" BorderBrush="Red" BorderThickness="4" CornerRadius="5" Margin="20" HorizontalAlignment="Center" VerticalAlignment="Center">  
    2.     <Image Width="200" Source="C:\Users\lenovo\Downloads\1.jpg" Stretch="Uniform" />  
    3.     <Border.Effect>  
    4.         <DropShadowEffect Color="Black" BlurRadius="16" ShadowDepth="0" Opacity="1" />  
    5.     </Border.Effect>  
    6. </Border>  
相關文章
相關標籤/搜索