public void BeginReversibleAnimation(Duration duration, RepeatBehavior repeat, int startIndex, int endIndex, bool reverse = false, bool autoReverse = false) { //if (!reverse && endIndex < startIndex) //{ // throw new ArgumentOutOfRangeException(string.Format( // "endIndex ({0}) не может быть меньше, чем startIndex ({1})", endIndex, startIndex)); //} IsPlaying = true; Duration restDuration = GetDurationPerFrames(duration, !reverse ? endIndex - startIndex : startIndex - endIndex); //Duration restDuration = GetDurationPerFrames(duration, !reverse ? endIndex - startIndex : startIndex - endIndex); //if (reverse) // _animation = new Int32Animation(endIndex, startIndex, restDuration); //else _animation = new Int32Animation(startIndex, endIndex, restDuration); _animation.AutoReverse = autoReverse; _animation.RepeatBehavior = repeat; _animation.Completed += ReversibleAnimation_Completed; BeginAnimation(FrameIndexProperty, _animation); }
private void GifImage_Initialized(object sender, EventArgs e) { gifDecoder = new GifBitmapDecoder(Uri, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); animation = new Int32Animation(0, gifDecoder.Frames.Count - 1, new Duration(new TimeSpan(0, 0, 0, gifDecoder.Frames.Count / 10, (int)((gifDecoder.Frames.Count / 10.0 - gifDecoder.Frames.Count / 10) * 1000)))); animation.RepeatBehavior = RepeatBehavior.Forever; Source = gifDecoder.Frames[0]; }
public GifImage(Uri uri) { gf = new GifBitmapDecoder(uri, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); anim = new Int32Animation(0, gf.Frames.Count - 1, new Duration(new TimeSpan(0, 0, 0, gf.Frames.Count / 12, (int)((gf.Frames.Count / 12.0 - gf.Frames.Count / 12) * 1000)))); anim.RepeatBehavior = RepeatBehavior.Forever; Source = gf.Frames[0]; }
private void InitFromUri(Uri uri) { if (uri == null) { _gifDecoder = null; _animation = null; _animationIsWorking = false; return; } var decoder = BitmapDecoder.Create(uri, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); _gifDecoder = decoder as GifBitmapDecoder; if (_gifDecoder != null) { _animation = new Int32Animation(0, _gifDecoder.Frames.Count - 1, new Duration(new TimeSpan(0, 0, 0, _gifDecoder.Frames.Count / 10, (int)((_gifDecoder.Frames.Count / 10.0 - _gifDecoder.Frames.Count / 10) * 1000)))) { RepeatBehavior = RepeatBehavior.Forever }; } else { _animation = null; _animationIsWorking = false; } Source = decoder.Frames[0]; }
//all user control "views" fade in and out the same way private static void FadeContentControl(FrameworkElement currentContentControl, bool fadeIn) { Storyboard userControlStoryboard = new Storyboard(); DoubleAnimation changeContentOpacity; Int32Animation changeContentIndex; Duration durationOpacity = new Duration(TimeSpan.FromMilliseconds(401)); Duration durationIndex = new Duration(TimeSpan.FromMilliseconds(0)); if (fadeIn) { changeContentOpacity = new DoubleAnimation(0, 1, durationOpacity); changeContentIndex = new Int32Animation(0, 3, durationIndex); changeContentIndex.BeginTime = TimeSpan.FromMilliseconds(0); } else { changeContentOpacity = new DoubleAnimation(1, 0, durationOpacity); changeContentIndex = new Int32Animation(3, 0, durationIndex); changeContentIndex.BeginTime = TimeSpan.FromMilliseconds(400); } //add to the storyboard userControlStoryboard.Children.Add(changeContentOpacity); userControlStoryboard.Children.Add(changeContentIndex); Storyboard.SetTarget(userControlStoryboard, currentContentControl); Storyboard.SetTargetProperty(changeContentOpacity, new PropertyPath("Opacity")); Storyboard.SetTargetProperty(changeContentIndex, new PropertyPath("(Panel.ZIndex)")); //animate this object userControlStoryboard.Begin(currentContentControl); }
/// <summary> /// Initializes a new instance of the <see cref="AnimatedLoader" /> class. /// </summary> public AnimatedLoader() { Visibility = Visibility.Hidden; IsVisibleChanged += LoaderVisibilityChanged; var imageSource = Application.Current.Resources["LoaderImage"] as ImageSource; var loaderUri = imageSource == null ? new Uri("pack://application:,,,/Nova;component/Resources/loader.gif", UriKind.Absolute) : new Uri(imageSource.ToString(), UriKind.Absolute); _gifBitmapDecoder = new GifBitmapDecoder(loaderUri, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); var seconds = _gifBitmapDecoder.Frames.Count / 10; var milliseconds = (int)(((_gifBitmapDecoder.Frames.Count / 10.0) - (_gifBitmapDecoder.Frames.Count / 10.0)) * 1000d); var timespan = new TimeSpan(0, 0, 0, seconds, milliseconds); var duration = new Duration(timespan); _animation = new Int32Animation(0, _gifBitmapDecoder.Frames.Count - 1, duration) { RepeatBehavior = RepeatBehavior.Forever }; Source = _gifBitmapDecoder.Frames[0]; Height = Source.Height; Width = Source.Width; }
/// <summary> /// Initializes this instance. /// </summary> private void Initialize() { if (string.IsNullOrEmpty(this.GifSource)) { // this.GifSource = "/LoadTariffs;component/Resources/Images/Windows8loader.gif"; this.GifSource = "/Umehluko.Tools.UI;component/Resources/Images/Windows8loader.gif"; } this._gifDecoder = new GifBitmapDecoder( new Uri("pack://application:,,," + this.GifSource), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); this._animation = new Int32Animation( 0, this._gifDecoder.Frames.Count - 1, new Duration( new TimeSpan( 0, 0, 0, this._gifDecoder.Frames.Count / 10, (int)((this._gifDecoder.Frames.Count / 10.0 - this._gifDecoder.Frames.Count / 10) * 1000)))) { RepeatBehavior = RepeatBehavior .Forever }; this.Source = this._gifDecoder.Frames[0]; this._isInitialized = true; }
/// <summary> /// 針對<paramref name="animatable"/>執行泛型動畫。 /// </summary> /// <typeparam name="PropertyType">執行動畫的屬性型別。</typeparam> /// <param name="animatable">要執行動畫的個體。</param> /// <param name="dp">要執行動畫的屬性。</param> /// <param name="to">屬性改變的目標值。</param> /// <param name="durationMs">動畫的時長。</param> public static void BeginAnimation <PropertyType>(this IAnimatable animatable, DependencyProperty dp, PropertyType to, double durationMs) { DependencyObject animation; var duration = TimeSpan.FromMilliseconds(durationMs); switch (to) { case int i: animation = new Int32Animation(i, duration); break; case double d: animation = new DoubleAnimation(d, duration); break; case Color color: animation = new ColorAnimation(color, duration); break; case Thickness thickness: animation = new ThicknessAnimation(thickness, duration); break; case Rect rect: animation = new RectAnimation(rect, duration); break; default: throw new NotSupportedException(); } animatable.BeginAnimation(dp, animation as AnimationTimeline); }
protected override void OnInitialized(EventArgs e) { gf = new GifBitmapDecoder(new Uri(Uri, UriKind.RelativeOrAbsolute), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); anim = new Int32Animation(0, gf.Frames.Count - 1, new Duration(new TimeSpan(0, 0, 0, gf.Frames.Count / (int)fps, (int)((gf.Frames.Count / (double)fps - gf.Frames.Count / (int)fps) * 1000)))); anim.RepeatBehavior = RepeatBehavior.Forever; Source = gf.Frames[0]; }
private void Initialize() { gifDecoder = new GifBitmapDecoder(new Uri("pack://application:,,," + this.Source), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); this.animation = new Int32Animation(0, this.gifDecoder.Frames.Count - 1, new Duration(new TimeSpan(0, 0, 0, this.gifDecoder.Frames.Count / 10, (int)((this.gifDecoder.Frames.Count / 10.0 - this.gifDecoder.Frames.Count / 10) * 1000)))); this.animation.RepeatBehavior = RepeatBehavior.Forever; base.Source = gifDecoder.Frames[0]; this.isInitialized = true; }
private void SetZIndex(IAnimatable image, TimeSpan beginTime, int value) { Int32Animation animation = new Int32Animation(value, new Duration(new TimeSpan(0))) { BeginTime = beginTime }; image.BeginAnimation(Panel.ZIndexProperty, animation); }
private void Initialize() { _gifDecoder = FASTBuildMonitorControl.GetGifBitmapDecoder(GifSource); _animation = new Int32Animation(0, _gifDecoder.Frames.Count - 1, new Duration(new TimeSpan(0, 0, 0, _gifDecoder.Frames.Count / 10, (int)((_gifDecoder.Frames.Count / 10.0 - _gifDecoder.Frames.Count / 10) * 1000)))); _animation.RepeatBehavior = RepeatBehavior.Forever; this.Source = _gifDecoder.Frames[0]; _isInitialized = true; }
private void Initialize() { _gifDecoder = new GifBitmapDecoder(new Uri("pack://application:,,," + this.GifSource), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); _animation = new Int32Animation(0, _gifDecoder.Frames.Count - 1, new Duration(new TimeSpan(0, 0, 0, _gifDecoder.Frames.Count / Time, (int)((_gifDecoder.Frames.Count / TimeD - _gifDecoder.Frames.Count / Time) * 1000)))); _animation.RepeatBehavior = RepeatBehavior.Forever; this.Source = _gifDecoder.Frames[0]; _isInitialized = true; }
private void BeginLengthAnimation() { Int32Animation lenani = new Int32Animation(); lenani.From = 0; lenani.To = 200; lenani.Duration = new Duration(TimeSpan.Parse("0:0:6")); this.BeginAnimation(ColorWindow.LengthProperty, lenani); }
private void Initialize() { _gifDecoder = new GifBitmapDecoder(new Uri(this.Source.ToString(Global.cultures)), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); _animation = new Int32Animation(0, _gifDecoder.Frames.Count - 1, new Duration(new TimeSpan(0, 0, 0, _gifDecoder.Frames.Count / 10, (int)((_gifDecoder.Frames.Count / 10.0 - _gifDecoder.Frames.Count / 10) * 1000)))); _animation.RepeatBehavior = RepeatBehavior.Forever; this.Source = _gifDecoder.Frames[0]; _isInitialized = true; }
protected override void OnInitialized(EventArgs e) { decoder = new GifBitmapDecoder(Uri, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); animation = new Int32Animation(0, decoder.Frames.Count - 1, new Duration(new TimeSpan(0, 0, 0, decoder.Frames.Count / 10, (int)((decoder.Frames.Count / 10.0 - decoder.Frames.Count / 10) * 1000)))) { RepeatBehavior = RepeatBehavior.Forever }; Source = decoder.Frames[0]; }
//ѕосле паузы анимаци¤ доходит до конца и запускаетс¤ снова в нормальном режиме //(после паузы меньше Duration задаЄтс¤, чтобы доиграть анимацию с той же скоростью protected void ForeverAnimationWithPause_Completed(object sender, EventArgs e) { var animation = (AnimationClock)sender; animation.Completed -= ForeverAnimationWithPause_Completed; _isForeverAnimationSubscribed = false; _animation = new Int32Animation(0, _brushes.Length - 1, _duration); _animation.RepeatBehavior = RepeatBehavior.Forever; BeginAnimation(FrameIndexProperty, _animation); }
void Initialize() { gifDecoder = new GifBitmapDecoder(new Uri(GifSource), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); animation = new Int32Animation(0, gifDecoder.Frames.Count - 1, new Duration(new TimeSpan(0, 0, 0, gifDecoder.Frames.Count / 10, (int)((gifDecoder.Frames.Count / 10.0 - gifDecoder.Frames.Count / 10) * 1000)))) { RepeatBehavior = RepeatBehavior.Forever }; Source = gifDecoder.Frames[0]; isInitialized = true; }
private void Initialize() { if (!string.IsNullOrEmpty(this.GifSource)) { _gifDecoder = new GifBitmapDecoder(new Uri(this.GifSource, UriKind.Absolute), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); _animation = new Int32Animation(0, _gifDecoder.Frames.Count - 1, new Duration(new TimeSpan(0, 0, 0, _gifDecoder.Frames.Count / 10, (int)((_gifDecoder.Frames.Count / 10.0 - _gifDecoder.Frames.Count / 10) * 1000)))); _animation.RepeatBehavior = RepeatBehavior.Forever; this.Source = _gifDecoder.Frames[0]; } _isInitialized = true; }
private void Initialize() { var src = ConfigurationManager.AppSettings["gif_loader_src"]; _gifDecoder = new GifBitmapDecoder(new Uri(src), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); _animation = new Int32Animation(0, _gifDecoder.Frames.Count - 1, new Duration(new TimeSpan(0, 0, 0, _gifDecoder.Frames.Count / 10, (int)((_gifDecoder.Frames.Count / 10.0 - _gifDecoder.Frames.Count / 10) * 1000)))); _animation.RepeatBehavior = RepeatBehavior.Forever; this.Source = _gifDecoder.Frames[0]; _isInitialized = true; }
/// <summary> /// Create an AnimationTimeline based on the number of keyframes in an image, /// without any duration specified per frame. /// </summary> /// <returns></returns> private AnimationTimeline BuildFrameAnimation(BitmapFrame[] frames, double secPerFrame = 0.1) { int len = frames.Length; Int32Animation frameAnimation = new Int32Animation(0, len - 1, new Duration(TimeSpan.FromSeconds(len * secPerFrame)) ); frameAnimation.RepeatBehavior = RepeatBehavior.Forever; return(frameAnimation); } //
private void InitializeGif() { try { if (GifSource != null) { vGifDecoder = BitmapDecoder.Create(GifSource, BitmapCreateOptions.None, BitmapCacheOption.OnLoad); vInt32Animation = new Int32Animation(0, vGifDecoder.Frames.Count - 1, new Duration(new TimeSpan(0, 0, 0, vGifDecoder.Frames.Count / 10, (int)((vGifDecoder.Frames.Count / 10.0 - vGifDecoder.Frames.Count / 10) * 1000)))); vInt32Animation.RepeatBehavior = RepeatBehavior.Forever; vInt32Animation.SpeedRatio = SpeedRatio; } } catch { } }
private void Initialize() { var imageSource = Application.Current.FindResource(GifSource) as BitmapImage; _gifDecoder = new GifBitmapDecoder(imageSource.UriSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); _animation = new Int32Animation(0, _gifDecoder.Frames.Count - 1, new Duration(new TimeSpan(0, 0, 0, _gifDecoder.Frames.Count / 10, (int)((_gifDecoder.Frames.Count / 10.0 - _gifDecoder.Frames.Count / 10) * 1000)))) { RepeatBehavior = RepeatBehavior.Forever }; Source = _gifDecoder.Frames[0]; _isInitialized = true; }
private void Initialize() { if (this.GifSource == "") { return; } gif = new Gif(this.GifSource); var decoder = gif.GetDecoder(); _animation = new Int32Animation(0, decoder.Frames.Count - 1, gif.GetTotalDuration()); _animation.RepeatBehavior = RepeatBehavior.Forever; this.Source = decoder.Frames[0]; _isInitialized = true; }
public void Initialize() { AutoStart = true; string gifImageSrc = (!string.IsNullOrWhiteSpace(GifSource)) ? GifSource : "Assets/progress.gif"; Uri gifUri = new Uri("pack://application:,,,/USDConfigurationMigration.WPF;component/" + gifImageSrc); _gifDecoder = new GifBitmapDecoder(gifUri, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); _animation = new Int32Animation(0, _gifDecoder.Frames.Count - 1, new Duration(new TimeSpan(0, 0, 0, _gifDecoder.Frames.Count / 20, (int)((_gifDecoder.Frames.Count / 20.0 - _gifDecoder.Frames.Count / 20) * 1000)))); _animation.RepeatBehavior = RepeatBehavior.Forever; this.Source = _gifDecoder.Frames[0]; _isInitialized = true; }
void Initialize() { gifDecoder = new GifBitmapDecoder(new Uri(GifSource), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); // ReSharper disable once PossibleLossOfFraction var timeSpan = new TimeSpan(0, 0, 0, gifDecoder.Frames.Count / 10, (int)((gifDecoder.Frames.Count / 10.0 - gifDecoder.Frames.Count / 10) * 1000)); var duration = new Duration(timeSpan); animation = new Int32Animation(0, gifDecoder.Frames.Count - 1, duration) { RepeatBehavior = RepeatBehavior.Forever }; Source = gifDecoder.Frames[0]; isInitialized = true; }
/// <summary> /// Show a message when a turn is skipped /// </summary> private void ShowPlayAgainMessage() { // can play again animation lblPlayAgain.Content = LogicalBoard.Instance.CurrentPlayer.Name + playAgainText; Storyboard sb = new Storyboard(); DoubleAnimation da1 = new DoubleAnimation() { From = 0.0, To = 1.0, Duration = TimeSpan.FromSeconds(0.5) }; Storyboard.SetTargetName(da1, playAgain.Name); Storyboard.SetTargetProperty(da1, new PropertyPath(Border.OpacityProperty)); DoubleAnimation da2 = new DoubleAnimation() { From = 1.0, To = 0.0, Duration = TimeSpan.FromSeconds(0.5) }; da2.BeginTime = TimeSpan.FromSeconds(3); Storyboard.SetTargetName(da2, playAgain.Name); Storyboard.SetTargetProperty(da2, new PropertyPath(Border.OpacityProperty)); //Index animation Int32Animation daIndex1 = new Int32Animation() { From = -1000, To = 1000, Duration = TimeSpan.FromSeconds(0.1) }; Storyboard.SetTargetName(daIndex1, playAgain.Name); Storyboard.SetTargetProperty(daIndex1, new PropertyPath(Panel.ZIndexProperty)); Int32Animation daIndex2 = new Int32Animation() { From = 1000, To = -1000, Duration = TimeSpan.FromSeconds(0.1) }; daIndex2.BeginTime = TimeSpan.FromSeconds(da2.BeginTime.Value.Seconds + da2.Duration.TimeSpan.Seconds); //start at the end of da2 Storyboard.SetTargetName(daIndex2, playAgain.Name); Storyboard.SetTargetProperty(daIndex2, new PropertyPath(Panel.ZIndexProperty)); sb.Children.Add(da1); sb.Children.Add(da2); sb.Children.Add(daIndex1); sb.Children.Add(daIndex2); sb.Begin(this); }
private void GifSourceChanged(string newSource) { if (_animation != null) { BeginAnimation(FrameIndexProperty, null); } _decoder = new GifBitmapDecoder(new Uri(newSource), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); Source = _decoder.Frames[0]; int count = _decoder.Frames.Count; _animation = new Int32Animation(0, count - 1, new Duration(new TimeSpan(0, 0, 0, count / 10, (int)((count / 10.0 - count / 10) * 50000)))); //10000 is equal to 1 second _animation.RepeatBehavior = RepeatBehavior.Forever; BeginAnimation(FrameIndexProperty, _animation); }
/// <summary> /// 在层次深度上移动精灵 /// </summary> /// <param name="sprite">精灵实例</param> /// <param name="duration">动画时长</param> /// <param name="fromZ">起始Z</param> /// <param name="toZ">目标Z</param> /// <param name="accZ">加速度Z</param> public static void ZMoveAnimation(YuriSprite sprite, Duration duration, int fromZ, int toZ, double accZ) { if (duration.TimeSpan.TotalMilliseconds == 0 || GlobalConfigContext.GAME_PERFORMANCE_TYPE == GlobalConfigContext.PerformanceType.NoEffect) { sprite.Descriptor.Z = sprite.Descriptor.ToZ; Canvas.SetZIndex(sprite.AnimationElement, sprite.Descriptor.ToZ); } else { Storyboard story = new Storyboard(); Int32Animation int32AniZ = new Int32Animation(fromZ, toZ, duration); if (accZ >= 0) { int32AniZ.AccelerationRatio = accZ; } else { int32AniZ.DecelerationRatio = -accZ; } if (sprite.Descriptor.ResourceType == ResourceType.Background) { Storyboard.SetTarget(int32AniZ, ViewManager.GetInstance().GetTransitionBox()); } else { Storyboard.SetTarget(int32AniZ, sprite.AnimationElement); } Storyboard.SetTargetProperty(int32AniZ, new PropertyPath(Canvas.ZIndexProperty)); story.Children.Add(int32AniZ); story.Duration = duration; story.FillBehavior = FillBehavior.Stop; story.Completed += (sender, args) => { sprite.Descriptor.Z = sprite.Descriptor.ToZ; Canvas.SetZIndex(sprite.AnimationElement, sprite.Descriptor.ToZ); }; sprite.AnimateCount++; SpriteAnimation.aniDict[story] = sprite; story.Completed += (sender, args) => { sprite.AnimateCount--; SpriteAnimation.aniDict.Remove(story); }; story.Begin(); } }
private void Initialize() { if (!File.Exists(GifSource)) { this.Source = GlobalVariable.DefaultBigImage; } else { gif = new Gif(this.GifSource); var decoder = gif.GetDecoder(); _animation = new Int32Animation(0, decoder.Frames.Count - 1, gif.GetTotalDuration()); _animation.RepeatBehavior = RepeatBehavior.Forever; this.Source = null; this.Source = gif.GetFirstFrame(); _isInitialized = true; } }