我们采用Genesis增加点阵字时,用Genesis增加Canned Text即可,但奥宝中文不支持,且字符种类是有限的呀
不过没关系,没有自己造呀。在这里我分享一种增加点阵字的实现方法
一.通过代码增加点阵字效果
二.实现代码
private void button1_Click(object sender, EventArgs e) { add Add = new add(); Font font = new Font("宋体", 12); Add.text_dot(font, "pcbren共赢加油"); }
/// <summary> /// 增加点阵字 /// </summary> /// <param name="font"></param> /// <param name="text"></param> /// <param name="x"></param> /// <param name="y"></param> /// <param name="symbols_size"></param> /// <param name="symbol"></param> /// <param name="scale"></param> public void text_dot(Font font, string text = "pcbren", double x = 0, double y = 0, double symbols_size = 500, string symbol = "r", double scale = 1) { y += 10; int txt_space = 12; double txt_sum = 0; foreach (char strt in text) { if (strt >= 0x4e00 && strt <= 0x9fbb) txt_space = 12; else txt_space = 8; bool[,] data = calc.text_dot_array(font, strt.ToString()); for (int i = 0; i <= data.GetLength(0) - 1; i++) { for (int j = 0; j <= data.GetLength(0) - 1; j++) { if (data[i, j]) { pad(i * scale + txt_sum, y * scale - j * scale, symbols_size, symbol); } } } txt_sum += txt_space * scale; } }
/// <summary> /// 计算文字点阵列 /// </summary> /// <param name="font"></param> /// <param name="text"></param> /// <returns></returns> public static bool[,] text_dot_array(Font font, string text = "pcbren") { int array_count = 20; bool[,] data = new bool[array_count, array_count]; Bitmap bmp = new Bitmap(array_count, array_count); Graphics g = Graphics.FromImage(bmp); g.Clear(Color.White); g.DrawString(text, font, Brushes.Black, 0, 0); StringBuilder sb = new StringBuilder(); for (int y = 0; y < array_count; y++) { sb.Append(" "); for (int x = 0; x < array_count; x++) { if (bmp.GetPixel(x, y).GetBrightness() > 0.5f) { sb.Append(" "); data[x, y] = false; } else { sb.Append("#"); data[x, y] = true; } } } return data; }