Пример #1
0
        /// <summary>
        /// Iterator can be used for large GIF-files in order to display progress bar.
        /// </summary>
        public static byte[] EncodeIteratorExample(Gif gif)
        {
            var bytes        = new List <byte>();
            var parts        = gif.EncodeIterator();
            var iteratorSize = gif.GetEncodeIteratorSize();
            var stopwatch    = new Stopwatch();
            var index        = 0;
            var time         = 0d;

            stopwatch.Start();

            foreach (var part in parts)
            {
                if (index == iteratorSize - 1)                 // GIF header should be placed to sequence start!
                {
                    bytes.InsertRange(0, part);
                }
                else
                {
                    bytes.AddRange(part);
                }

                stopwatch.Stop();
                time += stopwatch.Elapsed.TotalSeconds;

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

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

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

            return(bytes.ToArray());
        }