zoukankan      html  css  js  c++  java
  • PCB Genesis增加点阵字 实现原理

    我们采用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;
            }
  • 相关阅读:
    linux的vim按了ctrl+s之后假死的解决办法
    linux下的终端模拟器urxvt的配置
    vim下正则表达式的非贪婪匹配
    linux中的一个看图的软件
    解决windows的控制台显示utf8乱码的问题
    [PHP][位转换积累]之异或运算的简单加密应用
    [PHP][REDIS]phpredis 'RedisException' with message 'read error on connection'
    [PHP][位转换积累]之与运算截取二进制流的值
    [PHP][位转换积累]之pack和unpack
    [正则表达式]PCRE反向分组引用
  • 原文地址:https://www.cnblogs.com/pcbren/p/9435817.html
Copyright © 2011-2022 走看看