static string GenerateGif(long mostRecentGeneration, string saveDirectory, string imageDirectory, EvolutionEntities DBContext)
        {
            var e = new Gif.Components.AnimatedGifEncoder();

            String outputFilePath = saveDirectory + "\\progress-" + mostRecentGeneration.ToString() + ".gif";

            e.Start(outputFilePath);
            e.SetDelay(100);
            //-1:no repeat,0:always repeat
            e.SetRepeat(-1);



            var filenametemplate = imageDirectory + @"\{0}-{1}.jpg";

            foreach (var generation in DBContext.FamilyTrees.Where(x => x.WasSuccessful).OrderBy(x => x.Generation))
            {
                Bitmap bmp = new Bitmap(string.Format(filenametemplate, generation.Generation, generation.Child));
                DrawText(bmp, generation.Generation);
                e.AddFrame(bmp);
            }

            e.Finish();
            return(outputFilePath);
        }
        /// <summary>
        /// Saves the animation to the specified stream as an animated GIF.
        /// </summary>
        /// <param name="stream">The <see cref="Stream"/> where the animation
        /// will be saved.</param>
        public void Save(Stream stream)
        {
            using (var encoder = new Gif.Components.AnimatedGifEncoder(stream))
            {
                encoder.Delay = Delay;
                encoder.TransparentColor = TransparentColor;
                encoder.Repeat = 0;

                var frames = GetFrames();
                var i = 0;
                foreach (var item in frames)
                {
                    var frame = item; // Workaround for `ref`

                    if (Transformation != null)
                    {
                        OnTransformingFrame(frame, i);
                        Transformation.ApplyTo(ref frame);
                    }

                    if (!OnAddingFrame(frame, i)) break;
                    encoder.AddFrame(frame);

                    frame.Dispose();
                    i++;
                }
            }
        }