public static UIImage AnimateGif(CGImageSource source, nfloat scale, CGImageThumbnailOptions options, TaskParameter parameters) { if (source == null) { return(null); } var frameCount = source.ImageCount; // no need to animate, fail safe. if (frameCount <= 1) { using (var imageRef = source.CreateThumbnail(0, options)) { return(new UIImage(imageRef, scale, UIImageOrientation.Up)); } } var frames = GetFrames(source, options); var delays = GetDelays(source); var totalDuration = delays.Sum(); var adjustedFrames = AdjustFramesToSpoofDurations(frames, scale, delays, totalDuration); return(UIImage.CreateAnimatedImage(adjustedFrames.ToArray(), totalDuration / 100.0)); }
private static List <CoreGraphics.CGImage> GetFrames(CGImageSource source, CGImageThumbnailOptions options) { var retval = new List <CoreGraphics.CGImage>(); for (int i = 0; i < source?.ImageCount; i++) { var frameImage = source.CreateThumbnail(i, options); retval.Add(frameImage); } return(retval); }
static CoreGraphics.CGImage[] GetFrames(CGImageSource source, CGImageThumbnailOptions options) { var retval = new CoreGraphics.CGImage[source.ImageCount]; for (int i = 0; i < source.ImageCount; i++) { var frameImage = source.CreateThumbnail(i, options); retval[i] = frameImage; } return(retval); }
static CGImage CreateThumbnail (CGImageSource source, int maxPixelSize, CancellationToken token) { token.ThrowIfCancellationRequested (); return source.CreateThumbnail (0, new CGImageThumbnailOptions { CreateThumbnailWithTransform = true, CreateThumbnailFromImageAlways = true, MaxPixelSize = maxPixelSize, ShouldCache = false }); }