protected override Task <PImage> GenerateImageFromDecoderContainerAsync(IDecodedImage <PImage> decoded, ImageInformation imageInformation, bool isPlaceholder)
        {
            PImage result;

            if (decoded.IsAnimated)
            {
#if __IOS__
                result = PImage.CreateAnimatedImage(decoded.AnimatedImages
                                                    .Select(v => v.Image)
                                                    .Where(v => v?.CGImage != null).ToArray(), decoded.AnimatedImages.Sum(v => v.Delay) / 100.0);
#elif __MACOS__
                using (var mutableData = NSMutableData.Create())
                {
                    var fileOptions = new CGImageDestinationOptions
                    {
                        GifDictionary = new NSMutableDictionary()
                    };
                    fileOptions.GifDictionary[ImageIO.CGImageProperties.GIFLoopCount] = new NSString("0");
                    //options.GifDictionary[ImageIO.CGImageProperties.GIFHasGlobalColorMap] = new NSString("true");

                    using (var destintation = CGImageDestination.Create(mutableData, MobileCoreServices.UTType.GIF, decoded.AnimatedImages.Length, fileOptions))
                    {
                        for (var i = 0; i < decoded.AnimatedImages.Length; i++)
                        {
                            var options = new CGImageDestinationOptions
                            {
                                GifDictionary = new NSMutableDictionary()
                            };
                            options.GifDictionary[ImageIO.CGImageProperties.GIFUnclampedDelayTime] = new NSString(decoded.AnimatedImages[i].Delay.ToString());
                            destintation.AddImage(decoded.AnimatedImages[i].Image.CGImage, options);
                        }

                        destintation.Close();
                    }

                    result = new PImage(mutableData);

                    // TODO I really don't know why representations count is 1, anyone?
                    // var test = result.Representations();
                }
#endif
            }
            else
            {
                result = decoded.Image;
            }

            return(Task.FromResult(result));
        }
        protected override Task <PImage> GenerateImageFromDecoderContainerAsync(IDecodedImage <PImage> decoded, ImageInformation imageInformation, bool isPlaceholder)
        {
            PImage result;

            if (decoded.IsAnimated)
            {
#if __IOS__
                result = PImage.CreateAnimatedImage(decoded.AnimatedImages
                                                    .Select(v => v.Image)
                                                    .Where(v => v?.CGImage != null).ToArray(), decoded.AnimatedImages.Sum(v => v.Delay) / 100.0);
#elif __MACOS__
                using (var mutableData = NSMutableData.Create())
                {
                    using (var destintation = CGImageDestination.Create(mutableData, MobileCoreServices.UTType.GIF, decoded.AnimatedImages.Length))
                    {
                        for (int i = 0; i < decoded.AnimatedImages.Length; i++)
                        {
                            var options = new CGImageDestinationOptions();
                            options.GifDictionary = new NSMutableDictionary();
                            options.GifDictionary[ImageIO.CGImageProperties.GIFDelayTime] = NSNumber.FromDouble(decoded.AnimatedImages[i].Delay / 100.0d);

                            destintation.AddImage(decoded.AnimatedImages[i].Image.CGImage, options);
                        }
                        destintation.Close();
                    }

                    // TODO I really don't know why it's not working. Anyone?
                    result = new PImage(mutableData);
                }
#endif
            }
            else
            {
                result = decoded.Image;
            }

            return(Task.FromResult(result));
        }
 protected override Task <SharedEvasImage> GenerateImageFromDecoderContainerAsync(IDecodedImage <SharedEvasImage> decoded, ImageInformation imageInformation, bool isPlaceholder)
 {
     if (decoded.IsAnimated)
     {
         throw new NotImplementedException();
     }
     else
     {
         return(Task.FromResult(decoded.Image));
     }
 }
 protected abstract Task <TImageContainer> GenerateImageFromDecoderContainerAsync(IDecodedImage <TDecoderContainer> decoded, ImageInformation imageInformation, bool isPlaceholder);
        protected override Task <SelfDisposingBitmapDrawable> GenerateImageFromDecoderContainerAsync(IDecodedImage <Bitmap> decoded, ImageInformation imageInformation, bool isPlaceholder)
        {
            try
            {
                SelfDisposingBitmapDrawable result;

                if (decoded.IsAnimated)
                {
                    result = new FFGifDrawable(Context.Resources, decoded.AnimatedImages[0].Image, decoded.AnimatedImages);
                }
                else
                {
                    if (isPlaceholder)
                    {
                        result = new SelfDisposingBitmapDrawable(Context.Resources, decoded.Image);
                    }
                    else
                    {
                        result = new FFBitmapDrawable(Context.Resources, decoded.Image);
                    }
                }

                if (result == null || !result.HasValidBitmap)
                {
                    throw new BadImageFormatException("Not a valid bitmap");
                }

                return(Task.FromResult(result));
            }
            catch (Exception ex)
            {
                if (ex is Java.Lang.Throwable javaException && javaException.Class == Java.Lang.Class.FromType(typeof(Java.Lang.OutOfMemoryError)))
                {
                    throw new OutOfMemoryException();
                }

                throw;
            }
        }
Exemple #6
0
        protected override async Task <BitmapSource> GenerateImageFromDecoderContainerAsync(IDecodedImage <BitmapHolder> decoded, ImageInformation imageInformation, bool isPlaceholder)
        {
            if (decoded.IsAnimated)
            {
                throw new NotImplementedException();
            }
            else
            {
                try
                {
                    if (decoded.Image.HasWriteableBitmap)
                    {
                        return(decoded.Image.WriteableBitmap);
                    }

                    return(await decoded.Image.ToBitmapImageAsync().ConfigureAwait(false));
                }
                finally
                {
                    decoded.Image.FreePixels();
                    decoded.Image = null;
                }
            }
        }
Exemple #7
0
        protected virtual async Task <TImageContainer> GenerateImageAsync(string path, ImageSource source, IDecodedImage <object> decoded, ImageInformation imageInformation, bool enableTransformations, bool isPlaceholder)
        {
            var decoderContainer = new DecodedImage <TDecoderContainer>()
            {
                IsAnimated     = decoded.IsAnimated,
                Image          = decoded.Image as TDecoderContainer,
                AnimatedImages = decoded.AnimatedImages?.Select(
                    v => new AnimatedImage <TDecoderContainer>()
                {
                    Delay = v.Delay, Image = v.Image as TDecoderContainer
                })
                                 .ToArray()
            };

            if (enableTransformations && Parameters.Transformations != null && Parameters.Transformations.Count > 0)
            {
                var transformations = Parameters.Transformations.ToList();

                if (decoderContainer.IsAnimated)
                {
                    for (int i = 0; i < decoderContainer.AnimatedImages.Length; i++)
                    {
                        decoderContainer.AnimatedImages[i].Image = await TransformAsync(decoderContainer.AnimatedImages[i].Image, transformations, path, source, isPlaceholder);
                    }
                }
                else
                {
                    decoderContainer.Image = await TransformAsync(decoderContainer.Image, transformations, path, source, isPlaceholder);
                }
            }

            return(await GenerateImageFromDecoderContainerAsync(decoderContainer, imageInformation, isPlaceholder));
        }
Exemple #8
0
 protected override Task <MockBitmap> GenerateImageFromDecoderContainerAsync(IDecodedImage <MockBitmap> decoded, ImageInformation imageInformation, bool isPlaceholder)
 {
     return(Task.FromResult(new MockBitmap()));
 }
 public DataResolverResult(IDecodedImage <object> decoded, LoadingResult loadingResult, ImageInformation imageInformation)
 {
     Decoded          = decoded;
     LoadingResult    = loadingResult;
     ImageInformation = imageInformation;
 }