.net - 使用 WPF 在外发光上实现平滑动画

标签 .net wpf animation

我有 ToggleButton 并应用了 OuterGlowBitmapEffect。我对这种发光进行动画处理,使其具有脉动效果,吸引人们的注意力。我的问题是,如果我将动画放慢一秒钟,它就会卡顿很多。如何防止出现卡顿现象?是什么原因导致卡顿不流畅?

这是按钮:

<ToggleButton x:Name="btnMap1" Click="btnMap1_Click" Style="{DynamicResource GenericButton}" Width="152" Height="127" IsChecked="True">
    <ToggleButton.BitmapEffect>
        <OuterGlowBitmapEffect GlowColor="White" GlowSize="0" Noise="0" Opacity="1" />
    </ToggleButton.BitmapEffect>
</ToggleButton>

这是动画:

<Storyboard x:Key="ButtonGlow" RepeatBehavior="Forever" Timeline.DesiredFrameRate="30">
    <DoubleAnimation 
            BeginTime="00:00:00"
            Storyboard.TargetName="btnMap1"
            Storyboard.TargetProperty="(UIElement.BitmapEffect).(OuterGlowBitmapEffect.GlowSize)"
            From="0.0"
            To="10.0"
            Duration="0:0:1"
            AutoReverse="True"
            />
</Storyboard>

最佳答案

此效果非常消耗 CPU 资源,因为它是软件渲染的而不是 GPU 生成的。

Microsoft has deprecated this and similar effects and discourages their use .

Bitmap effects should not be applied to large visuals or animations because this can degrade performance.

他们建议使用BlurEffect相反。

关于.net - 使用 WPF 在外发光上实现平滑动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3368234/

相关文章:

java - 编程决定 java 或 .Net,db 或无 db

c# - Monitor.Pulse 和 Monitor.Wait 之间的竞争条件?

c# - 以编程方式对 wpf 数据网格进行排序

Java 图形 : setClip vs clipRect vs repaint(int, 整数、整数、整数)

ios - UIAnimate 只在按钮上发生一次

javascript - 为多个用户同步正在进行的轮盘动画

c# - 默认情况下,LINQ 和 Entity Framework 加载的渴望程度如何?

C# 将多个参数传递给 BAT 文件

wpf - 将 PNG 文件导入 Wpf Canvas

c# - 在 C# 中的多个对象之间共享一个实例化类