Example #1
0
        /// <summary>
        /// generate multiple frames of the cursor (|) based on a loop iterations
        /// </summary>
        /// <param name="writer">VideoFileWriter (open) for adding the frames</param>
        /// <param name="sentence">Sentence object with the empty and full cursor png images</param>
        /// <param name="interations">number of iterations 2 iterations equal to half a second frame</param>
        private void SetCursorBlink(VideoFileWriter writer, Sentences sentence, int interations)
        {
            var emptyCursor = sentence.CursorEmpty;
            var fullCursor  = sentence.CursorFull;

            for (int i = 0; i < interations; i++)
            {
                writer.WriteVideoFrame(LoadImageToMemory(emptyCursor.FullName));
                writer.WriteVideoFrame(LoadImageToMemory(emptyCursor.FullName));

                writer.WriteVideoFrame(LoadImageToMemory(fullCursor.FullName));
                writer.WriteVideoFrame(LoadImageToMemory(fullCursor.FullName));
            }
        }
Example #2
0
        /// <summary>
        /// generate multiple frames of the cursor (|) based on a loop iterations
        /// </summary>
        /// <param name="writer">VideoFileWriter (open) for adding the frames</param>
        /// <param name="sentence">Sentence object with the empty and full cursor png images</param>
        /// <param name="interations">number of iterations 2 iterations equal to half a second frame</param>
        private void SetCursorBlink(AnimatedGifEncoder writer, Sentences sentence, int interations)
        {
            var emptyCursor = sentence.CursorEmpty;
            var fullCursor  = sentence.CursorFull;

            for (int i = 0; i < interations; i++)
            {
                var emptyCursorFrame = new Bitmap(emptyCursor.FullName);
                writer.AddFrame(emptyCursorFrame);
                writer.AddFrame(emptyCursorFrame);

                var fullCursorFrame = new Bitmap(fullCursor.FullName);
                writer.AddFrame(fullCursorFrame);
                writer.AddFrame(fullCursorFrame);
            }
        }
Example #3
0
        public IEnumerable <Sentences> GetSentences()
        {
            var di     = new DirectoryInfo(_path);
            var images = di.GetFiles().Where(c => c.Extension == ".png").Select(v => new { SentenceId = v.Name.Split('-')[0], Info = v });

            var grouped = images.GroupBy(b => b.SentenceId);
            var list    = new List <Sentences>();

            foreach (var item in grouped)
            {
                var sentence = new Sentences();
                sentence.SentenceNumber = item.Key;
                sentence.CursorFull     = item.Where(b => b.Info.Name.Contains("cursorFull")).SingleOrDefault().Info;
                sentence.CursorEmpty    = item.Where(b => b.Info.Name.Contains("cursorEmpty")).SingleOrDefault().Info;
                sentence.SentenceFile   = item.Where(b => !b.Info.Name.Contains("cursor")).Select(b => b.Info)
                                          .OrderBy(b => int.Parse(Path.GetFileNameWithoutExtension(b.Name.Split('-')[1])));
                list.Add(sentence);
            }

            return(list);
        }
Example #4
0
        /// <summary>
        /// Generate a typly gif
        /// </summary>
        public void MakeGif()
        {
            string gifName = _path + "\\typly.gif";

            AnimatedGifEncoder e = new AnimatedGifEncoder();

            e.Start(gifName);
            e.SetFrameRate(12);
            e.SetRepeat(0); //-1:no repeat,0:always repeat

            var images = GetSentences();

            Sentences currentSentence = null;

            foreach (var item in images)
            {
                if (currentSentence != null && item.SentenceNumber != currentSentence.SentenceNumber)
                {
                    foreach (var reversedImage in currentSentence.SentenceFile.Reverse())
                    {
                        e.AddFrame(new Bitmap(reversedImage.FullName));
                    }
                }

                foreach (var image in item.SentenceFile)
                {
                    e.AddFrame(new Bitmap(image.FullName));
                }

                SetCursorBlink(e, item, 2);
                currentSentence = item;
            }
            //add last frame of cursor blinking for 2 seconds
            var twoCursors = images.Last();

            SetCursorBlink(e, twoCursors, 6);

            e.Finish();
        }
Example #5
0
        /// <summary>
        /// Generate a .mp4 typly video
        /// </summary>
        /// <param name="framesPerSecond"></param>
        public void MakeVideo(int framesPerSecond = 10)
        {
            VideoFileWriter writer = new VideoFileWriter();

            writer.Open(_path + "\\typly.mp4", _width, _height, framesPerSecond, VideoCodec.MPEG4, 1000000);

            var images = GetSentences().ToList();

            Sentences currentSentence = null;

            foreach (var item in images)
            {
                if (currentSentence != null && item.SentenceNumber != currentSentence.SentenceNumber)
                {
                    foreach (var reversedImage in currentSentence.SentenceFile.Reverse())
                    {
                        writer.WriteVideoFrame(LoadImageToMemory(reversedImage.FullName));
                    }
                }

                foreach (var image in item.SentenceFile)
                {
                    writer.WriteVideoFrame(LoadImageToMemory(image.FullName));
                }

                SetCursorBlink(writer, item, 2);
                currentSentence = item;
            }

            //add last frame of cursor blinking for 2 seconds
            var twoCursors = images.Last();

            SetCursorBlink(writer, twoCursors, 6);

            writer.Close();
        }