Ejemplo n.º 1
0
        public async Task <Bitmap> LoadImageAsync(Xamarin.Forms.ImageSource imageSource, Context context, CancellationToken cancellationToken = default)
        {
            try
            {
                if (!IsValid(context))
                {
                    return(null);
                }

                var source = ImageSourceBinding.GetImageSourceBinding(imageSource, null);
                if (source == null)
                {
                    return(null);
                }

                var result = await LoadImageAsync(source, imageSource, context, cancellationToken);

                var target = result.Target as BitmapTarget;
                return(target?.BitmapDrawable?.Bitmap);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Ejemplo n.º 2
0
        async void UpdateImage(Image imageView, CachedImage image, CachedImage previousImage)
        {
            CancelIfNeeded();

            if (image == null || imageView == null)
            {
                return;
            }

            var ffSource = await ImageSourceBinding.GetImageSourceBinding(image.Source, image).ConfigureAwait(false);

            if (ffSource == null)
            {
                if (_lastImageSource == null)
                {
                    return;
                }

                _lastImageSource = null;
                imageView.Source = null;
                return;
            }

            if (previousImage != null && !ffSource.Equals(_lastImageSource))
            {
                _lastImageSource = null;
                imageView.Source = null;
            }

            image.SetIsLoading(true);

            var placeholderSource = await ImageSourceBinding.GetImageSourceBinding(image.LoadingPlaceholder, image).ConfigureAwait(false);

            var errorPlaceholderSource = await ImageSourceBinding.GetImageSourceBinding(image.ErrorPlaceholder, image).ConfigureAwait(false);

            image.SetupOnBeforeImageLoading(out TaskParameter imageLoader, ffSource, placeholderSource, errorPlaceholderSource);

            if (imageLoader != null)
            {
                var finishAction = imageLoader.OnFinish;
                var sucessAction = imageLoader.OnSuccess;

                imageLoader.Finish((work) =>
                {
                    finishAction?.Invoke(work);
                    ImageLoadingSizeChanged(image, false);
                });

                imageLoader.Success((imageInformation, loadingResult) =>
                {
                    sucessAction?.Invoke(imageInformation, loadingResult);
                    _lastImageSource = ffSource;
                });

                imageLoader.LoadingPlaceholderSet(() => ImageLoadingSizeChanged(image, true));

                _currentTask = imageLoader.Into(imageView);
            }
        }
        public override bool Equals(object obj)
        {
            ImageSourceBinding imageSourceBinding = obj as ImageSourceBinding;

            if (imageSourceBinding == null)
            {
                return(false);
            }
            return(ImageSource == imageSourceBinding.ImageSource && Path == imageSourceBinding.Path && Stream == imageSourceBinding.Stream);
        }
Ejemplo n.º 4
0
        private async void UpdateImage(Image imageView, CachedImage image, CachedImage previousImage)
        {
            CancelIfNeeded();
            if (image == null || imageView == null || _isDisposed)
            {
                return;
            }
            ImageSourceBinding ffSource = await ImageSourceBinding.GetImageSourceBinding(image.Source, image)
                                          .ConfigureAwait(continueOnCapturedContext: false);

            if (ffSource == null)
            {
                if (_lastImageSource != null)
                {
                    _lastImageSource = null;
                    imageView.Source = null;
                }
                return;
            }
            if (previousImage != null && !ffSource.Equals(_lastImageSource))
            {
                _lastImageSource = null;
                imageView.Source = null;
            }
            image.SetIsLoading(isLoading: true);
            ImageSourceBinding placeholderSource = await ImageSourceBinding.GetImageSourceBinding(image.LoadingPlaceholder, image).ConfigureAwait(continueOnCapturedContext: false);

            ImageSourceBinding errorPlaceholderSource = await ImageSourceBinding.GetImageSourceBinding(image.ErrorPlaceholder, image).ConfigureAwait(continueOnCapturedContext: false);

            image.SetupOnBeforeImageLoading(out var imageLoader, ffSource, placeholderSource, errorPlaceholderSource);
            if (imageLoader != null)
            {
                Action <IScheduledWork> finishAction = imageLoader.OnFinish;
                Action <ImageInformation, LoadingResult> sucessAction = imageLoader.OnSuccess;
                imageLoader.Finish(delegate(IScheduledWork work)
                {
                    finishAction?.Invoke(work);
                    ImageLoadingSizeChanged(image, isLoading: false);
                });
                imageLoader.Success(delegate(ImageInformation imageInformation, LoadingResult loadingResult)
                {
                    sucessAction?.Invoke(imageInformation, loadingResult);
                    _lastImageSource = ffSource;
                });
                imageLoader.LoadingPlaceholderSet(delegate
                {
                    ImageLoadingSizeChanged(image, isLoading: true);
                });
                if (!_isDisposed)
                {
                    _currentTask = imageLoader.Into(imageView);
                }
            }
        }
Ejemplo n.º 5
0
        void UpdateImage()
        {
            if (IsDisposed)
            {
                return;
            }

            CancelIfNeeded();

            var ffSource = ImageSourceBinding.GetImageSourceBinding(Element.Source, Element);

            if (ffSource == null)
            {
                Control.Source = null;
                return;
            }

            Element.SetIsLoading(true);
            Control.Source = null;

            var placeholderSource      = ImageSourceBinding.GetImageSourceBinding(Element.LoadingPlaceholder, Element);
            var errorPlaceholderSource = ImageSourceBinding.GetImageSourceBinding(Element.ErrorPlaceholder, Element);

            TaskParameter imageLoader;

            Element.SetupOnBeforeImageLoading(out imageLoader, ffSource, placeholderSource, errorPlaceholderSource);
            if (imageLoader != null)
            {
                var finishAction = imageLoader.OnFinish;
                var sucessAction = imageLoader.OnSuccess;

                imageLoader.Success((imageInformation, loadingResult) =>
                {
                    sucessAction?.Invoke(imageInformation, loadingResult);
                });

                imageLoader.Finish((work) =>
                {
                    finishAction?.Invoke(work);
                    OnLoadFinished();
                });

                _currentTask = imageLoader.Into(Control);
            }
        }
Ejemplo n.º 6
0
        public async Task <PImage> LoadImageAsync(Xamarin.Forms.ImageSource imageSource, CancellationToken cancellationToken = default, float scale = 1)
        {
            try
            {
                var source = ImageSourceBinding.GetImageSourceBinding(imageSource, null);
                if (source == null)
                {
                    return(null);
                }

                var result = await LoadImageAsync(source, imageSource, null, cancellationToken).ConfigureAwait(false);

                var target = result?.Target as PImageTarget;
                return(target?.PImage);
            }
            catch (Exception)
            {
                return(null);
            }
        }
        public Task LoadImageAsync(Xamarin.Forms.ImageSource imageSource, ImageView imageView, CancellationToken cancellationToken = default)
        {
            try
            {
                if (!IsValid(imageView))
                {
                    return(Task.CompletedTask);
                }

                var source = ImageSourceBinding.GetImageSourceBinding(imageSource, null);
                if (source == null)
                {
                    imageView.SetImageResource(Android.Resource.Color.Transparent);
                    return(Task.CompletedTask);
                }

                return(LoadImageAsync(source, imageSource, imageView, cancellationToken));
            }
            catch (Exception)
            {
                return(Task.CompletedTask);
            }
        }
Ejemplo n.º 8
0
        private void UpdateImage(PImageView imageView, CachedImage image, CachedImage previousImage)
        {
            lock (_updateBitmapLock)
            {
                CancelIfNeeded();

                if (image == null || imageView == null || imageView.Handle == IntPtr.Zero || _isDisposed)
                {
                    return;
                }

                var ffSource = ImageSourceBinding.GetImageSourceBinding(image.Source, image);
                if (ffSource == null)
                {
                    if (_lastImageSource == null)
                    {
                        return;
                    }

                    _lastImageSource = null;
                    imageView.Image  = null;
                    return;
                }

                if (previousImage != null && !ffSource.Equals(_lastImageSource))
                {
                    _lastImageSource = null;
                    imageView.Image  = null;
                }

                image.SetIsLoading(true);

                var placeholderSource      = ImageSourceBinding.GetImageSourceBinding(image.LoadingPlaceholder, image);
                var errorPlaceholderSource = ImageSourceBinding.GetImageSourceBinding(image.ErrorPlaceholder, image);
                image.SetupOnBeforeImageLoading(out var imageLoader, ffSource, placeholderSource, errorPlaceholderSource);

                if (imageLoader != null)
                {
                    var finishAction = imageLoader.OnFinish;
                    var sucessAction = imageLoader.OnSuccess;

                    imageLoader.Finish((work) =>
                    {
                        finishAction?.Invoke(work);
                        ImageLoadingSizeChanged(image, false);
                    });

                    imageLoader.Success((imageInformation, loadingResult) =>
                    {
                        sucessAction?.Invoke(imageInformation, loadingResult);
                        _lastImageSource = ffSource;
                    });

                    imageLoader.LoadingPlaceholderSet(() => ImageLoadingSizeChanged(image, true));

                    if (!_isDisposed)
                    {
                        _currentTask = imageLoader.Into(imageView);
                    }
                }
            }
        }