目录
Gif动态呈现
推荐GitHub开源库:WpfAnimatedGif
主要功能介绍
var control = WpfAnimatedGif.ImageBehavior.GetAnimationController(img);//获取控制对象
control.Play();//控制播放control.Pause();//暂停
control.GotoFrame(control.FrameCount - 1);//到指定帧
control.CurrentFrameChanged//帧改变触发事件
WpfAnimatedGif.ImageBehavior.SetAnimatedSource(img,bitmapImage);//指定gif源
WpfAnimatedGif.ImageBehavior.SetAnimationSpeedRatio(img, speed);//控制速率
gif:ImageBehavior.AutoStart="False"//是否自动播放
gif:ImageBehavior.RepeatBehavior=“3x"//重复播放次数
gif:ImageBehavior.AnimationLoaded//动画加载时触发事件
gif:ImageBehavior.AnimationCompleted//动画结束触发事件
示例代码
C#后置代码:
private void Button_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.InitialDirectory = Directory.GetCurrentDirectory();
openFileDialog.Filter = "图片类型|*.jpg;*.jpeg;*.gif";
openFileDialog.ShowDialog();
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.UriSource = new Uri(openFileDialog.FileName);
bitmapImage.EndInit();
WpfAnimatedGif.ImageBehavior.SetAnimatedSource(img,bitmapImage);
}
XAML:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="3*" />
<RowDefinition />
</Grid.RowDefinitions>
<Image x:Name="img"
gif:ImageBehavior.AutoStart="False"
gif:ImageBehavior.RepeatBehavior="Forever" />
<StackPanel Grid.Row="1" Orientation="Horizontal">
<Button Grid.Column="1"
Width="80"
Height="80"
BorderBrush="Peru"
BorderThickness="5"
Click="Button_Click"
FontSize="20"
FontWeight="DemiBold">
Open
</Button>
<Button Grid.Column="1"
Width="80"
Height="80"
BorderBrush="Green"
BorderThickness="5"
Click="Button_Click_1"
FontSize="20"
FontWeight="DemiBold">
Play
</Button>
<Button Grid.Column="1"
Width="80"
Height="80"
BorderBrush="Green"
BorderThickness="5"
Click="Button_Click_2"
FontSize="20"
FontWeight="DemiBold">
Pause
</Button>
&l

本文介绍了如何在WPF应用中使用WpfAnimatedGif库处理GIF动态图,包括控制播放、暂停、设置速率等,还展示了图形效果滤镜、变形、3D圆、Path绘制以及长方形多方式填充的使用方法和代码示例。

1481

被折叠的 条评论
为什么被折叠?



