Last active
March 23, 2021 20:10
-
-
Save beliy26/c9ddbd33e5eaf94285e5 to your computer and use it in GitHub Desktop.
Image to text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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