private static void computeLevels() { grayLevels = new int[AsciiArt.characterSet.Length]; Font font = AsciiArt.GetFont(); glyphs = new List <Glyph>(); for (int lvl = 0; lvl < AsciiArt.characterSet.Length; lvl++) { string s = AsciiArt.characterSet[lvl].ToString(); Bitmap bmp = new Bitmap(100, 100); Graphics g = Graphics.FromImage(bmp); g.Clear(Color.White); g.DrawString(s, font, Brushes.Black, 0, 0); int width = (int)g.MeasureString("#", font).Width - 2; int height = (int)g.MeasureString("#", font).Height; int totalGray = 0; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { Color col = bmp.GetPixel(x, y); int value = Draw.RgbToGray(col.R, col.G, col.B); totalGray += value; } } int grayLevel = (int)(255f * (float)totalGray / (float)(width * height * 255)); glyphs.Add(new Glyph(characterSet[lvl], grayLevel)); } glyphs.Sort(delegate(Glyph g1, Glyph g2) { return(g1.level.CompareTo(g2.level)); }); levelsComputed = true; }
private void btnConvert_Click(object sender, EventArgs e) { int w = 100, h = 100; int.TryParse(txtWidth.Text, out w); int.TryParse(txtHeight.Text, out h); string text = AsciiArt.Process(inputImage, w, h, textParam.Text); Font fnt = AsciiArt.GetFont(); Output dlgOut = new Output(); dlgOut.WndText = text; dlgOut.Fnt = fnt; dlgOut.ShowDialog(); }