读取字体文件 模拟显卡点阵显示汉字

来源:互联网 发布:ntp服务器配置 linux 编辑:程序博客网 时间:2024/05/16 15:04
        static void Main(string[] args)        {            /*字符以16*16的显存显示 因为32字节 32*8=256 恰好可以用256位来模拟*/            //区码word[0] 位码word[1]            byte[] word = Encoding.Default.GetBytes("他");            //汉字在字符库中的位置 一个字符占32字节 因为文件是要以字节读入内存的 所以要算出字符相对于文件的字节偏移            int qh = word[0] - 0xa0;            int wh = word[1] - 0xa0;            int offset = ((qh - 1) * 94 + (wh - 1)) * 32;            byte[] lib=File.ReadAllBytes(System.Environment.CurrentDirectory + "\\HZK16");            byte[] buffer = lib.Skip(offset).Take(32).ToArray();            Byte[] key = new Byte[] { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };            for (int i = 0; i < 32; i++)            {                for (int j = 0; j < 8; j++)                {                    string ss = (buffer[i] & key[j]) == 0 ? "○" : "●";                    Console.Write(ss);                                }                if (i % 2 == 1) {                    Console.Write("\r\n");                }            }            Console.ReadKey();        }

0 0
原创粉丝点击