public APNGAnimationProvider(string path, Dispatcher uiDispatcher) : base(path, uiDispatcher)
        {
            var decoder = new APNGBitmap(path);

            if (decoder.IsSimplePNG)
            {
                _imageMagickProvider = new ImageMagickProvider(path, uiDispatcher);
                return;
            }

            _frames         = new List <FrameInfo>(decoder.Frames.Length);
            _renderedFrames = new List <BitmapSource>(decoder.Frames.Length);
            Enumerable.Repeat(0, decoder.Frames.Length).ForEach(_ => _renderedFrames.Add(null));

            Animator = new Int32AnimationUsingKeyFrames {
                RepeatBehavior = RepeatBehavior.Forever
            };

            var wallclock = TimeSpan.Zero;

            for (var i = 0; i < decoder.Frames.Length; i++)
            {
                var frame = decoder.Frames[i];

                _frames.Add(new FrameInfo(decoder.IHDRChunk, frame));

                Animator.KeyFrames.Add(new DiscreteInt32KeyFrame(i, KeyTime.FromTimeSpan(wallclock)));
                wallclock += _frames[i].Delay;
            }
        }
示例#2
0
        private static AnimationProvider LoadFullImageCore(Uri path, Dispatcher uiDispatcher)
        {
            byte[] sign;
            using (var reader =
                       new BinaryReader(new FileStream(path.LocalPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
            {
                sign = reader.BaseStream.Length < 4 ? new byte[] { 0, 0, 0, 0 } : reader.ReadBytes(4);
            }

            AnimationProvider provider;

            if (sign[0] == 'G' && sign[1] == 'I' && sign[2] == 'F' && sign[3] == '8')
            {
                provider = new GifAnimationProvider(path.LocalPath, uiDispatcher);
            }
            else if (sign[0] == 0x89 && sign[1] == 'P' && sign[2] == 'N' && sign[3] == 'G')
            {
                provider = new APNGAnimationProvider(path.LocalPath, uiDispatcher);
            }
            else
            {
                provider = new ImageMagickProvider(path.LocalPath, uiDispatcher);
            }

            return(provider);
        }
        public override void Dispose()
        {
            if (_imageMagickProvider != null)
            {
                _imageMagickProvider.Dispose();
                _imageMagickProvider = null;
                return;
            }

            _frames.Clear();
            _renderedFrames.Clear();
        }