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:
Enjoy it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
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(); } } } |
🙂