Example #1
0
 private static bool ParseArgs(string[] args)
 {
     if (args != null && args.Length > 0)
     {
         path = args[0];
         if (path.StartsWith("http"))
         {
             HelpersAscii.SaveBitmapFromUrl(path);
             is_from_Web = true;
             path        = Path.GetFileName(path);
         }
         if (args.Length > 1)
         {
             foreach (string s in args)
             {
                 if (s.StartsWith("-v"))
                 {
                     verbose = true;
                 }
                 if (s.StartsWith("-s"))
                 {
                     if (s.Length > 2 && s.StartsWith("-s="))
                     {
                         save_to_text = s.Replace("-s=", "");
                     }
                     else
                     {
                         save_to_text = path.Replace(Path.GetExtension(path), ".txt");
                     }
                 }
                 else if (s.StartsWith("-a"))
                 {
                     nearest_factor = int.Parse(s.Replace("-a", ""));
                     nearest_factor = Math.Max(0, Math.Min(nearFac_List.Length - 1, nearest_factor));
                 }
                 else if (s.StartsWith("-t"))
                 {
                     black_threshold = int.Parse(s.Replace("-t", ""));
                 }
                 else if (s.StartsWith("-d"))
                 {
                     if (is_from_Web)
                     {
                         delete_file_after = true;
                     }
                 }
             }
         }
         return(true);
     }
     else
     {
         Console.WriteLine("Syntax: scroller 'Image_Path' [Options]");
         Console.WriteLine("\t-a0 = (0-3)Nearest Neighbaor Factor");
         Console.WriteLine("\t-t50 = Black Threshold");
         Console.WriteLine("\t-d Delete file after finishing (only if File is from Web)");
         Console.WriteLine("\t-s Save to TextFile(Name is \"FileName\".txt");
         return(false);
     }
 }
Example #2
0
        private static string Create_ASCII_Art()
        {
            Bitmap b = new Bitmap(new Bitmap(path), HelpersAscii.Bounds.Width * 2, HelpersAscii.Bounds.Height * 2);

            string output = "";

            if (verbose)
            {
                Console.SetCursorPosition(0, 0);
            }
            for (int y = 0; y < b.Height; y++)
            {
                for (int x = 0; x < b.Width; x++)
                {
                    int hue = GetBrightness(b, x, y);

                    if (verbose)
                    {
                        Point p = HelpersAscii.ClampPosition(x / 2, y / 2);
                        Console.SetCursorPosition(p.X, p.Y);
                    }
                    char c = GetChar(hue);
                    output += c;
                }
                output += "\r\n";
            }
            return(output);
        }
Example #3
0
        private static void CreateHueDictionary()
        {
            if (!File.Exists("chars.txt"))
            {
                Bitmap       b    = new Bitmap(100, 100);
                Font         font = new Font(FontFamily.GenericMonospace, 24f, FontStyle.Bold);
                Graphics     g    = Graphics.FromImage(b);
                StreamWriter sw   = new StreamWriter(File.Create("chars.txt"));
                for (char c = ' '; c < 255; c++)
                {
                    if (char.IsControl(c))
                    {
                        continue;
                    }
                    g = Graphics.FromImage(b);
                    SizeF sf = g.MeasureString(c.ToString(), font);
                    b = new Bitmap((int)sf.Width, (int)sf.Height);
                    g.Dispose();
                    g = Graphics.FromImage(b);
                    g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed;
                    g.TextRenderingHint  = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;
                    g.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
                    g.Clear(Color.Black);
                    g.DrawString(c.ToString(), font, Brushes.White, 0, 0);
                    g.Dispose();

                    float f   = HelpersAscii.CalculateAverageBrightness(b);
                    int   val = (int)(f * 1000);
                    if (!chars.ContainsKey(val))
                    {
                        chars.Add(val, c);
                        sw.WriteLine(c.ToString() + val.ToString());
                    }
                }
                sw.Close();
            }
            else
            {
                string[] sa = File.ReadAllLines("chars.txt");
                foreach (string s in sa)
                {
                    chars.Add(int.Parse(s.Substring(1)), s[0]);
                }
            }
            max_dict_key = chars.Keys.Max();
        }