Ejemplo n.º 1
0
        /// <summary>
        /// Iterator can be used for large GIF-files in order to display progress bar.
        /// </summary>
        public static Gif DecodeIteratorExample()
        {
            var bytes     = File.ReadAllBytes(Path);
            var parts     = Gif.DecodeIterator(bytes);
            var frames    = new List <GifFrame>();
            var stopwatch = new Stopwatch();
            var index     = 0;
            var time      = 0d;

            stopwatch.Start();

            foreach (var frame in parts)
            {
                frames.Add(frame);
                stopwatch.Stop();
                time += stopwatch.Elapsed.TotalSeconds;

                Console.WriteLine("GIF frame #{0} loaded in {1:n4}s", index++, stopwatch.Elapsed.TotalSeconds);

                stopwatch.Reset();
                stopwatch.Start();
            }

            Console.WriteLine("GIF loaded with iterator in {0:n4}s", time);

            return(new Gif(frames));
        }
        public IEnumerator Start()
        {
            var bytes        = File.ReadAllBytes(LargeSample);
            var iterator     = Gif.DecodeIterator(bytes);
            var iteratorSize = Gif.GetDecodeIteratorSize(bytes);
            var frames       = new List <GifFrame>();
            var index        = 0f;

            foreach (var frame in iterator)
            {
                frames.Add(frame);
                ProgressFill.fillAmount = ++index / iteratorSize;
                yield return(null);
            }

            var gif = new Gif(frames);

            AnimatedImage.Play(gif);
        }
Ejemplo n.º 3
0
        public void Start()
        {
            var       bytes    = File.ReadAllBytes(LargeSample);
            var       iterator = Gif.DecodeIterator(bytes);
            Texture2D texture  = null;

            foreach (var frame in iterator)
            {
                texture = frame.Texture;
                break;
            }

            if (texture == null)
            {
                return;
            }

            Image.sprite = Sprite.Create(texture, new Rect(0f, 0f, texture.width, texture.height), new Vector2(0.5f, 0.5f), 100f);
        }