WPF 实现各种滤镜效果

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>
        
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition/>
        Grid.ColumnDefinitions>
        
        <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>

运行效果:

WPF 实现各种滤镜效果_第1张图片

总结:

消耗的GPU效果应该不错,有待验证。

源文件
动态链接库

你可能感兴趣的:(WPF)