1

I'm trying that the animation starts at specific frame with WpfAnimatedGif

The specific frame is 13 the gif has 30 frames

(when the animation will play I want that it will play from the beginning and then return to frame 13)

Frame 13 is for being like thumbnail and when I hover the gif the gif start to play and after that, it returns to frame 13 and act like thumbnail

(Their Git Page, Their documentation page)

XAML:

<Image Name="MinimizeGIF" gif:ImageBehavior.AutoStart="False" gif:ImageBehavior.RepeatBehavior="3x" gif:ImageBehavior.AnimatedSource="/Media/arrow_bottom1.gif" MouseEnter="MinimizeGIF_MouseEnter" Height="58.262" Margin="460.674,60.801,68.004,0" VerticalAlignment="Top" Width="71.321" MouseDown="MinimizeGIF_MouseDown" MouseLeave="MinimizeGIF_MouseLeave" RenderTransformOrigin="0.5,0.5" Loaded="MinimizeGIF_Loaded">
    <Image.RenderTransform>
        <TransformGroup>
            <ScaleTransform/>
            <SkewTransform/>
            <RotateTransform Angle="180"/>
            <TranslateTransform/>
        </TransformGroup>
    </Image.RenderTransform>
</Image>

C# code:

private void MinimizeGIF_Loaded(object sender, RoutedEventArgs e)
{
    var image = new BitmapImage();
    image.BeginInit();
    image.UriSource = new Uri(@"C:\Users\Me\Documents\Visual Studio 2017\Projects\Counting\Counting\arrow_bottom1.gif");
    image.EndInit();
    ImageBehavior.SetAnimatedSource(MinimizeGIF, image);
    var controller = ImageBehavior.GetAnimationController(MinimizeGIF);
    controller.GotoFrame(13); // It Goes to The Frame
    MessageBox.Show(controller.CurrentFrame.ToString());  // Just for the function to stop and after that the gif return to frame 0
}

At MessageBox.Show(controller.CurrentFrame.ToString()); it's showing me -1

Can please someone help me?

Raz Luvaton
  • 3,166
  • 4
  • 21
  • 36

2 Answers2

2
  1. Get the specific frame you want in image
  2. Create a button with this image
  3. When hovering the button change the btn1.Visibility = System.Windows.Visibility.Hidden; and start the gif from the beginning
  4. When leaving the button, change to btn1.Visibility = System.Windows.Visibility.Visible;
  • Tbh that is not a good solution at all. First off all of it uses too many resouces because you just simply cover the mediaelement and it is still playing in the background and a mediaelement is a heavy control. Furthermore have you thought about what you do if you hover the button to show the medialement playing, then leave it and then hover the button again? In your solution it will show the gif either at the end or at some random point playing. What is your idea how to properly play the mediaelement again from the beginning? – L. Guthardt Jul 16 '17 at 13:10
1

Again updated answer, because i have gathered some information. Have a look at my own question about this topic to convince you that it is not possible to change the position of a gif in a MediaElement.

L. Guthardt
  • 1,990
  • 6
  • 22
  • 44
  • thank you for the answer can you at my edit - the bold text for clarifying my Q? – Raz Luvaton Jul 10 '17 at 14:59
  • I am a bit confused, what exactly do you want to achieve? Way1: Do you want to display in generell the 13th image and when you hover it, it starts playing the gif from image 0? or Way2: The first time the gif starts playing from the 13th image and after that it will always play from image 0? Tell me your needs so that i can provide you a suitable solution. – L. Guthardt Jul 10 '17 at 22:42