C# – Animate a ASCII picture in Console

I was searching for a way to animate a picture in the C# console and I managed to find something quite good here.

Then it was quite easy, to do the animation – the key was in the adding of the line Thread.Sleep(100) and including the using System.Threading. Pretty much this is how the code works:

PrintPictureInConsole

Enjoy it:

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Diagnostics;
using System.Threading;

namespace ConsoleImage
{
    class Program
    {
        static void Main()
        {
            Image Picture = Image.FromFile("pictures/vIT.png"); //Here we may put anything, this is just for testing purposes. :)
            Console.SetBufferSize((Picture.Width * 0x2), (Picture.Height * 0x2));
            Console.WindowWidth = 180;
            Console.WindowHeight = 61;

            FrameDimension Dimension = new FrameDimension(Picture.FrameDimensionsList[0x0]);
            int FrameCount = Picture.GetFrameCount(Dimension);
            int Left = Console.WindowLeft, Top = Console.WindowTop;
            char[] Chars = { '#', '#', '@', '%', '=', '+', '*', ':', '-', '.', ' ' };
            Picture.SelectActiveFrame(Dimension, 0x0);
            for (int i = 0x0; i < Picture.Height; i++)
            {
                for (int x = 0x0; x < Picture.Width; x++)
                {
                    Color Color = ((Bitmap)Picture).GetPixel(x, i);
                    int Gray = (Color.R + Color.G + Color.B) / 0x3;
                    int Index = (Gray * (Chars.Length - 0x1)) / 0xFF;
                    Console.Write(Chars[Index]);
                }
                Console.Write('\n');
                Thread.Sleep(50);
            }
            Console.SetCursorPosition(Left, Top);
            Console.Read();
        }
    }
}

🙂