• 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;
            }
  • 相关阅读:
    58到家数据库30条军规解读
    mysql那些事(6) WHERE条件 字符串的引号
    按照ID倒序查出某个字段不重复的集合
    mysql那些事(5)建表存储引擎的选择
    mysql那些事(4)建库建表编码的选择
    mysql那些事(3)小数如何存储
    mysql那些事(2)时间类型数据如何存储
    Failed to install apk on device timeout
    daemon not running. starting it now on port 5037 ADB server didn't ACK
    webview
  • 原文地址:https://www.cnblogs.com/pcbren/p/9435817.html
Copyright © 2020-2023  润新知