[WPF] Display animated GIF images in WPF

JEONGKI'S Note·2023년 2월 8일
0

원본 : https://stackoverflow.com/questions/210922/how-do-i-get-an-animated-gif-to-work-in-wpf

Nuget package available here: WpfAnimatedGif.

A simple library to display animated GIF images in WPF, usable in XAML or in code.

It's very easy to use: in XAML, instead of setting the Source property, set the AnimatedSource attached property to the image you want:

<Window x:Class="WpfAnimatedGif.Demo.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:gif="http://wpfanimatedgif.codeplex.com"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Image gif:ImageBehavior.AnimatedSource="Images/animated.gif" />

You can also specify the repeat behavior (the default is 0x, which means it will use the repeat count from the GIF metadata):

        <Image gif:ImageBehavior.RepeatBehavior="3x"
               gif:ImageBehavior.AnimatedSource="Images/animated.gif" />

And of course you can also set the image in code:

var image = new BitmapImage();
image.BeginInit();
image.UriSource = new Uri(fileName);
image.EndInit();
ImageBehavior.SetAnimatedSource(img, image);
profile
주니어 개발자 공부노트입니다 :)

0개의 댓글