Ejemplo n.º 1
0
        public async Task <IDecodedImage <Bitmap> > DecodeAsync(Stream stream, string path, ImageSource source, ImageInformation imageInformation, TaskParameter parameters)
        {
            var result = new DecodedImage <Bitmap>();
            var helper = new PlatformGifHelper();

            await helper.ReadGifAsync(stream, path, parameters);

            result.IsAnimated = helper.Frames.Count > 1;

            if (result.IsAnimated && Configuration.AnimateGifs)
            {
                result.AnimatedImages = new AnimatedImage <Bitmap> [helper.Frames.Count];

                for (int i = 0; i < helper.Frames.Count; i++)
                {
                    var animatedImage = new AnimatedImage <Bitmap>();
                    animatedImage.Delay      = helper.Frames[i].Delay;
                    animatedImage.Image      = helper.Frames[i].Image;
                    result.AnimatedImages[i] = animatedImage;
                }
            }
            else
            {
                result.IsAnimated = false;
                result.Image      = helper.Frames[0].Image;
            }

            return(result);
        }
Ejemplo n.º 2
0
        async Task <FFGifDrawable> PlatformGenerateGifImageAsync(string path, ImageSource source, Stream imageData, ImageInformation imageInformation, bool enableTransformations, bool isPlaceholder)
        {
            if (imageData == null)
            {
                throw new ArgumentNullException(nameof(imageData));
            }

            ThrowIfCancellationRequested();

            try
            {
                var gifDecoder = new PlatformGifHelper();

                await gifDecoder.ReadGifAsync(imageData, Parameters, (bmp) =>
                {
                    return(PlatformTransformAsync(path, source, enableTransformations, isPlaceholder, bmp));
                });

                ThrowIfCancellationRequested();
                var bitmap = gifDecoder.GetBitmap();
                ThrowIfCancellationRequested();
                return(new FFGifDrawable(Context.Resources, bitmap, gifDecoder));
            }
            finally
            {
                imageData.TryDispose();
            }
        }
Ejemplo n.º 3
0
        public async Task <IDecodedImage <Bitmap> > DecodeAsync(Stream stream, string path, ImageSource source, ImageInformation imageInformation, TaskParameter parameters)
        {
            var result = new DecodedImage <Bitmap>();
            var helper = new PlatformGifHelper();

            await helper.ReadGifAsync(stream, path, parameters);

            result.IsAnimated = helper.Frames.Count > 1;

            if (result.IsAnimated && Configuration.AnimateGifs)
            {
                result.AnimatedImages = new AnimatedImage <Bitmap> [helper.Frames.Count];

                for (int i = 0; i < helper.Frames.Count; i++)
                {
                    var animatedImage = new AnimatedImage <Bitmap>
                    {
                        Delay = helper.Frames[i].Delay,
                        Image = helper.Frames[i].Image
                    };
                    result.AnimatedImages[i] = animatedImage;
                }
            }
            else
            {
                result.IsAnimated = false;
                result.Image      = helper.Frames[0].Image;
            }

            if (result.Image != null)
            {
                imageInformation.SetOriginalSize(result.Image.Width, result.Image.Height);
                imageInformation.SetCurrentSize(result.Image.Width, result.Image.Height);
            }
            else if (result.AnimatedImages != null)
            {
                if (result.AnimatedImages.Length > 0)
                {
                    if (result.AnimatedImages[0].Image != null)
                    {
                        imageInformation.SetOriginalSize(result.AnimatedImages[0].Image.Width, result.AnimatedImages[0].Image.Height);
                        imageInformation.SetCurrentSize(result.AnimatedImages[0].Image.Width, result.AnimatedImages[0].Image.Height);
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 4
0
 internal FFGifDrawable(Resources resources, Bitmap bitmap, PlatformGifHelper gifHelper) : base(resources, bitmap)
 {
     GifHelper = gifHelper;
 }