Skip to content

Instantly share code, notes, and snippets.

@beliy26
Last active March 23, 2021 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save beliy26/c9ddbd33e5eaf94285e5 to your computer and use it in GitHub Desktop.
Save beliy26/c9ddbd33e5eaf94285e5 to your computer and use it in GitHub Desktop.
Image to text
using System;
using System.Drawing;
using System.Drawing.Imaging;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Image Picture = Image.FromFile(@"1352.gif");
Console.SetBufferSize((Picture.Width * 0x2), (Picture.Height * 0x2));
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');
}
Console.SetCursorPosition(Left, Top);
Console.Read();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment