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]; }
private string sample28(ICanvasRenderingContext2D ctx) { Thread.Sleep(interval); dragon = new FlyingDragon(surface); // Create the animation targetting the StrokeDashOffset property var anima = new Int32Animation { Duration = new Duration(TimeSpan.FromSeconds(20)), FillBehavior = FillBehavior.Stop, From = 0, By = 1, To = 1000 }; // DesiredFrameRate can help reduce CPU cost and improve smoothness. // It can also cause beating if used improperly. Use with caution! //Timeline.DesiredFrameRateProperty.OverrideMetadata(typeof(Timeline), new FrameworkPropertyMetadata { DefaultValue = 120 }); Timeline.SetDesiredFrameRate(anima, 20); // 20 fps // Final per-figure setup Storyboard.SetTarget(anima, dragon); //Storyboard.SetDesiredFrameRate(anima, 10); Storyboard.SetTargetProperty(anima, new PropertyPath(FlyingDragon.IndexProperty)); storyboard.Children.Add(anima); // Begin the animation storyboard.Begin(); IsStarted = true; return string.Empty; }
/// <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; }
private static void AnimationFunction_Changed(DependencyObject d, DependencyPropertyChangedEventArgs e) { Int32Animation a = (Int32Animation)d; a._isAnimationFunctionValid = false; a.PropertyChanged(e.Property); }
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 / 10, (int)((gf.Frames.Count / 10.0 - gf.Frames.Count / 10) * 1000)))); anim.RepeatBehavior = RepeatBehavior.Forever; Source = gf.Frames[0]; }
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]; }
public GifImage() { Uri uri = new Uri("pack://application:,,,/AssortmentManagement;component/Images/load.gif"); 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 / 10, (int)((gf.Frames.Count / 10.0 - gf.Frames.Count / 10) * 1000)))); anim.RepeatBehavior = RepeatBehavior.Forever; Source = gf.Frames[0]; }
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 / 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 onInitialized(object sender, EventArgs e) { gf = new GifBitmapDecoder(new Uri(GifUri), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); var millisecondPerFrame = 1000.0 / Convert.ToDouble(FramesPerSecond); anim = new Int32Animation(0, gf.Frames.Count - 1, TimeSpan.FromMilliseconds(millisecondPerFrame * gf.Frames.Count)) { RepeatBehavior = RepeatBehavior.Forever }; Source = gf.Frames[0]; }
protected override void OnInitialized(EventArgs e) { base.OnInitialized(e); var stream = Application.GetResourceStream(new Uri(Source.ToString())); m_gf = new GifBitmapDecoder(stream.Stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); m_anim = new Int32Animation(0, m_gf.Frames.Count - 1, new Duration(new TimeSpan(0, 0, 0, m_gf.Frames.Count / 10, (int)((m_gf.Frames.Count / 10.0 - m_gf.Frames.Count / 10) * 1000)))); m_anim.RepeatBehavior = RepeatBehavior.Forever; Source = m_gf.Frames[0]; }
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]; }
private void Initialize() { if (!DesignerProperties.GetIsInDesignMode(this)) { _gifDecoder = new GifBitmapDecoder(new Uri("pack://application:,,,/OAuth;component/" + 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; } }
public void setGifSource(string url) { // initialize the gifDecoder _gifDecoder = new GifBitmapDecoder(new Uri(url), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); // initialize the animation _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)))); // repeat forever _animation.RepeatBehavior = RepeatBehavior.Forever; // set the image source this.Source = _gifDecoder.Frames[0]; this.StartAnimation(); }
private void RefreshGif() { if (string.IsNullOrEmpty(_gifSource?.ToString())) return; _gf = new GifBitmapDecoder(_gifSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); _anim = new Int32Animation(0, _gf.Frames.Count - 1, new Duration(TimeSpan.FromSeconds(_gf.Frames.Count/FramesPerSecond))) { RepeatBehavior = RepeatBehavior.Forever }; Source = _gf.Frames[0]; }
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) * 1000)))); _animation.RepeatBehavior = RepeatBehavior.Forever; BeginAnimation(FrameIndexProperty, _animation); }
internal ExplosionImage() { var random = new Random(); particles = new List<Particle>(); for (var i = 0; i < random.Next(10, 20); i++) { particles.Add(new Particle(new Point(Width / 2, Height / 2), random)); } boundsRect = new Rect(0, 0, Width, Height); boundsDrawing = new GeometryDrawing(); boundsDrawing.Brush = new SolidColorBrush(Color.FromArgb(0, 255, 255, 255)); boundsDrawing.Geometry = new RectangleGeometry(boundsRect); var frameAnimation = new Int32Animation(); frameAnimation.Duration = new Duration(TimeSpan.FromSeconds(5)); frameAnimation.To = (int)frameAnimation.Duration.TimeSpan.TotalMilliseconds; frameAnimation.Completed += FrameAnimation_Completed; BeginAnimation(FrameProperty, frameAnimation); }
/// <summary> /// Starts frame animation only if frames count is bigger than 1. /// </summary> /// <param name="image"></param> private static void StartFramesAnimation(this Image image) { BitmapFrame bitmapFrame = image.Source as BitmapFrame; if(bitmapFrame != null) { int framesCount = bitmapFrame.Decoder.Frames.Count; if(framesCount > 1) { Int32Animation gifAnimation = new Int32Animation( 0, // "From" value framesCount - 1, // "To" value new Duration(TimeSpan.FromMilliseconds(MILLISCONDS_PER_FRAME * framesCount)) ); gifAnimation.RepeatBehavior = RepeatBehavior.Forever; image.BeginAnimation(CurrentFrameIndexProperty, gifAnimation, HandoffBehavior.SnapshotAndReplace); } } }
/// <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; }
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() { if (string.IsNullOrEmpty(GifSource)) { StopAnimation(); return; } _gifDecoder = new GifBitmapDecoder(new Uri("pack://application:,,," + this.GifSource), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); _animation = new Int32Animation(0, 5 * (_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; if (AutoStart) { StartAnimation(); } }
private void Initialize() { decoder = new GifBitmapDecoder( new Uri("pack://application:,,," + GifSource), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); int frameCount = decoder.Frames.Count; animation = new Int32Animation( 0, decoder.Frames.Count - 1, new Duration(new TimeSpan(0, 0, 0, 0, frameCount * 100))) {RepeatBehavior = RepeatBehavior.Forever}; Source = decoder.Frames[0]; isInitialized = true; if (AutoStart && Visibility == Visibility.Visible) { StartAnimation(); } }
/// <summary> /// The animate. /// </summary> private void Animate() { try { if (this.storyboard != null) { this.storyboard.Stop(); this.storyboard.Remove(); } this.PreviousSelectedIndex = -1; this.PreviousSelectedItem = null; this.SelectedIndexProxy = 0; if ((this.ItemsSource != null) && (this.content != null)) { int count = this.ItemsSource.Cast<object>().Count(); this.storyboard = new Storyboard(); Int32Animation intAnimation = new Int32Animation() { Duration = this.Duration, FillBehavior = System.Windows.Media.Animation.FillBehavior.HoldEnd, From = 0, To = count - 1 }; Storyboard.SetTarget(intAnimation, this); Storyboard.SetTargetProperty(intAnimation, new PropertyPath("SelectedIndexProxy")); this.storyboard.Children.Add(intAnimation); this.IsFlipping = true; this.storyboard.Completed += this.OnFlippingCompleted; this.storyboard.Begin(); } } catch { } }
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 ClearAnimation() { if (Animation != null) BeginAnimation(FrameIndexProperty, null); Animation = null; this.Frames = null; }
private void PrepareAnimation() { Animation = new Int32Animation(0, this.Frames.Count - 1, new Duration(TimeSpan.FromMilliseconds(Frames.Count * 100))) { RepeatBehavior = RepeatBehavior.Forever }; base.Source = this.Frames[0]; BeginAnimation(FrameIndexProperty, Animation); }
private void PrepareAnimation(System.Windows.Media.Imaging.BitmapImage aBitmapImage) { System.Diagnostics.Debug.Assert(aBitmapImage != null); if (aBitmapImage.UriSource != null) { Decoder = new GifBitmapDecoder( aBitmapImage.UriSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); } else { aBitmapImage.StreamSource.Position = 0; Decoder = new GifBitmapDecoder( aBitmapImage.StreamSource, 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 }; base.Source = Decoder.Frames[0]; BeginAnimation(FrameIndexProperty, Animation); IsAnimationWorking = 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( TimeSpan.FromMilliseconds( ((ushort)(_gifDecoder.Frames[0].Metadata as BitmapMetadata).GetQuery("/grctlext/Delay")) * 10 * _gifDecoder.Frames.Count))) { RepeatBehavior = RepeatBehavior.Forever }; this.Source = _gifDecoder.Frames[0]; _isInitialized = true; }