WPF的界面呈現能力非常強大,能實現很多Photoshop能實現的濾鏡效果。通過使用UIElement的Effect屬性來實現。首先下載ShaderEffectLibrary庫。這個庫在Codeplex上,下載速度比較慢,而且這個網站快要關閉了,微軟準備遷移到GitHub上。這是一個開源庫。下載下來後使一些源代碼和資源。我編譯成了dll方便以後自己使用。仿照的是劉鐵猛的《深入淺出WPF》,在此作記錄,方便以後自己查找,使用Demo如下:
xaml代碼如下:
<Window x:Class="繪圖和動畫.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:繪圖和動畫"
xmlns:selib="clr-namespace:ShaderEffectLibrary;assembly=ShaderEffectLibrary"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<!--Layout-->
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<!--Content-->
<Image Source="Fighter.jpg" Margin="15" Grid.Column="0">
<Image.Effect>
<!--自帶效果-->
<DropShadowEffect BlurRadius="10" Opacity="0.75"/>
</Image.Effect>
</Image>
<Image Source="Fighter.jpg" Margin="15" Grid.Column="1">
<Image.Effect>
<!--效果庫中的效果效果-->
<selib:ZoomBlurEffect Center="0.5,0.5" BlurAmount="0.2"/>
</Image.Effect>
</Image>
</Grid>
</Window>
運行效果:
總結:
消耗的GPU效果應該不錯,有待驗證。