CreateAsync() public static method

public static CreateAsync ( Stream sourceStream, RepeatBehavior repeatBehavior, Image image ) : Task
sourceStream Stream
repeatBehavior RepeatBehavior
image Image
return Task
Esempio n. 1
0
        private static async void InitAnimationAsync(Image image, Stream stream, RepeatBehavior repeatBehavior, int seqNum)
        {
            if (!CheckDesignMode(image, null, stream))
            {
                return;
            }

            try
            {
                var animator = await ImageAnimator.CreateAsync(stream, repeatBehavior, image);

                // Check that the source hasn't changed while we were loading the animation
                if (GetSeqNum(image) != seqNum)
                {
                    animator.Dispose();
                    return;
                }

                SetAnimatorCore(image, animator);
                OnLoaded(image);
                await StartAsync(image, animator);
            }
            catch (InvalidSignatureException)
            {
                SetStaticImage(image, stream);
                OnLoaded(image);
            }
            catch (Exception ex)
            {
                OnError(image, ex, AnimationErrorKind.Loading);
            }
        }
Esempio n. 2
0
        private static async void InitAnimationAsync(Image image, Uri sourceUri, RepeatBehavior repeatBehavior, int seqNum)
        {
            if (!CheckDesignMode(image, sourceUri, null))
            {
                return;
            }

            try
            {
                var progress = new Progress <int>(percentage => OnDownloadProgress(image, percentage));
                var animator = await ImageAnimator.CreateAsync(sourceUri, repeatBehavior, progress, image);

                // Check that the source hasn't changed while we were loading the animation
                if (GetSeqNum(image) != seqNum)
                {
                    animator.Dispose();
                    return;
                }

                SetAnimatorCore(image, animator);
                OnLoaded(image);
                await StartAsync(image, animator);
            }
            catch (InvalidSignatureException)
            {
                await SetStaticImageAsync(image, sourceUri);

                OnLoaded(image);
            }
            catch (Exception ex)
            {
                OnError(image, ex, AnimationErrorKind.Loading);
            }
        }
        private static async void InitAnimationAsync(Image image, Uri sourceUri, RepeatBehavior repeatBehavior, int seqNum)
        {
            if (!CheckDesignMode(image, sourceUri, null))
            {
                return;
            }

            try
            {
                var progress = new Progress <int>(percentage => OnDownloadProgress(image, percentage));
                var animator = await ImageAnimator.CreateAsync(sourceUri, repeatBehavior, progress, image);

                // Check that the source hasn't changed while we were loading the animation
                if (GetSeqNum(image) != seqNum)
                {
                    animator.Dispose();
                    return;
                }
                await SetAnimatorCoreAsync(image, animator);

                OnLoaded(image);
            }
            catch (InvalidSignatureException)
            {
                var bmp = new BitmapImage();
#if WPF
                bmp.BeginInit();
                bmp.UriSource   = sourceUri;
                bmp.CacheOption = BitmapCacheOption.OnLoad;
                bmp.EndInit();
#elif WINRT || SILVERLIGHT
                bmp.UriSource = sourceUri;
#endif
                image.Source = bmp;
                OnLoaded(image);
            }
            catch (Exception ex)
            {
                OnError(image, ex, AnimationErrorKind.Loading);
            }
        }
        private static async void InitAnimationAsync(Image image, Stream stream, RepeatBehavior repeatBehavior, int seqNum)
        {
            if (!CheckDesignMode(image, null, stream))
            {
                return;
            }

            try
            {
                var animator = await ImageAnimator.CreateAsync(stream, repeatBehavior, image);
                await SetAnimatorCoreAsync(image, animator);

                // Check that the source hasn't changed while we were loading the animation
                if (GetSeqNum(image) != seqNum)
                {
                    animator.Dispose();
                    return;
                }
                OnLoaded(image);
            }
            catch (InvalidSignatureException)
            {
                var bmp = new BitmapImage();
#if WPF
                bmp.BeginInit();
                bmp.StreamSource = stream;
                bmp.EndInit();
#elif WINRT
                bmp.SetSource(stream.AsRandomAccessStream());
#elif SILVERLIGHT
                bmp.SetSource(stream);
#endif
                image.Source = bmp;
                OnLoaded(image);
            }
            catch (Exception ex)
            {
                OnError(image, ex, AnimationErrorKind.Loading);
            }
        }