private void SwitchGifPngAnimate(object sender, RoutedEventArgs e)
        {
            //洗版动画Gif图
            BitmapImage bitmapImage1 = new BitmapImage(new Uri("pack://application:,,,/Pr60_TestFunction;component/F02_ShowImage/GifImg/trending_animation_s1.gif"));
            Image       imgGif       = new Image();

            ImageBehavior.SetAnimatedSource(imgGif, bitmapImage1);
            ImageBehavior.SetRepeatBehavior(imgGif, new RepeatBehavior(1));
            grid30.Children.Add(imgGif);

            ImageAnimationController gifController = null;

            //******** GetAnimationController will return null if the animation is not yet fully loaded ***********
            ImageBehavior.AddAnimationLoadedHandler(imgGif, new RoutedEventHandler((s2, e2) =>
            {
                gifController = ImageBehavior.GetAnimationController(imgGif);
            }));


            //静态PNG图
            Image       imgPng       = new Image();
            BitmapImage bitmapImage2 = new BitmapImage(new Uri("pack://application:,,,/Pr60_TestFunction;component/F02_ShowImage/GifImg/text display_256x64_1.png"));

            imgPng.Source     = bitmapImage2;
            imgPng.Visibility = Visibility.Collapsed;
            grid30.Children.Add(imgPng);

            //计时器
            dispatcherTimer.Interval = new TimeSpan(0, 0, 2);
            dispatcherTimer.Tick    += (object s3, EventArgs e3) =>
            {
                //grid30.Children[0].Visibility = Visibility.Visible;
                //grid30.Children[1].Visibility = Visibility.Collapsed;
                imgGif.Visibility = Visibility.Visible;
                imgPng.Visibility = Visibility.Collapsed;

                dispatcherTimer.Stop();

                gifController.GotoFrame(0);
                gifController.Play();
            };

            ImageBehavior.AddAnimationCompletedHandler(imgGif, new RoutedEventHandler((s1, e1) =>
            {
                //grid30.Children[0].Visibility = Visibility.Collapsed;
                //grid30.Children[1].Visibility = Visibility.Visible;
                imgGif.Visibility = Visibility.Collapsed;
                imgPng.Visibility = Visibility.Visible;

                //gifController.Pause();
                dispatcherTimer.Start();
            }));


            //dispatcherTimer.Tick += new EventHandler((object s3, EventArgs e3) => PngEnd(s3, e3));
            //ImageBehavior.AddAnimationCompletedHandler(imgGif, new RoutedEventHandler((object s1, RoutedEventArgs e1) => GifEnd(s1, e1)));
        }
Beispiel #2
0
        public MediaElementControls(FileData file)
        {
            mLoadedTask = new TaskCompletionSource <MediaElementControls>();
            mFile       = file;

            App.FirstChanceDispatcherException += _HandleDispatcherException;

            mDimensions = file.Metadata.Dimensions;
            mImage      = new Image
            {
                Stretch = Stretch.Uniform,
                Width   = file.Metadata.Dimensions.Width,
                Height  = file.Metadata.Dimensions.Height,
            };
            mImage.DpiChanged += _HandleDpiChanged;
            ImageBehavior.AddAnimationLoadedHandler(mImage, _HandleAnimationLoaded);
            ImageBehavior.SetAutoStart(mImage, false);
            ImageBehavior.SetRepeatBehavior(mImage, RepeatBehavior.Forever);
            ImageBehavior.SetAnimatedSource(mImage, new BitmapImage(file.Uri));

            Brush = new VisualBrush(mImage);
        }
        public ShowGifImage()
        {
            InitializeComponent();
            Image img = new Image();

            BitmapImage bitmapImage = new BitmapImage(new Uri("pack://application:,,,/Pr60_TestFunction;component/F02_ShowImage/GifImg/theme_2_animation.gif"));
            Image       image       = new Image();

            image.Margin = new Thickness(10);
            ImageBehavior.SetAnimatedSource(image, bitmapImage);

            Slider slider = new Slider();

            slider.Maximum       = 3;
            slider.Minimum       = 1;
            slider.Value         = 2;
            slider.Orientation   = Orientation.Horizontal;
            slider.Width         = 300;
            slider.SmallChange   = 1;
            slider.TickFrequency = 1;

            /******* Control Layout ********/
            mainGrid.Children.Add(image);
            Grid.SetRow(image, 0);
            Grid.SetColumn(image, 1);

            StackPanel sp = new StackPanel
            {
                Orientation = Orientation.Vertical,
                Background  = Brushes.Beige
            };

            TextBlock txt = new TextBlock();

            txt.FontSize            = 20;
            txt.Margin              = new Thickness(6);
            txt.HorizontalAlignment = HorizontalAlignment.Center;
            txt.Text = "showSpeed";


            mainGrid.Children.Add(sp);
            Grid.SetRow(sp, 1);
            Grid.SetColumn(sp, 1);
            sp.Children.Add(slider);
            sp.Children.Add(txt);

            Binding bind = new Binding();

            bind.Source = slider;
            bind.Path   = new PropertyPath(Slider.ValueProperty);
            bind.Mode   = BindingMode.Default;
            txt.SetBinding(TextBlock.TextProperty, bind);

            // 将Gif动画的速度值绑定到Slider上
            Binding bindspeed = new Binding();

            bindspeed.Source = slider;
            bindspeed.Path   = new PropertyPath(Slider.ValueProperty);
            image.SetBinding(ImageBehavior.AnimationSpeedRatioProperty, bindspeed);


            //Grid0/3
            BitmapImage bitmapImage03 = new BitmapImage(new Uri("pack://application:,,,/Pr60_TestFunction;component/F02_ShowImage/GifImg/theme_2_animation.gif"));

            image.Margin = new Thickness(10);
            ImageBehavior.SetAnimatedSource(image03, bitmapImage03);
            gif.Children.Add(image03);


            // Get the speed ratio of gif.
            ImageBehavior.AddAnimationLoadedHandler(ImgS3, new RoutedEventHandler((s2, e2) =>
            {
                gifSpeedController = ImageBehavior.GetAnimationController(ImgS3);
            }));
        }