字符的点阵显示(模拟户外广告显示屏)
                       字符的点阵显示
 
                                                 电子科技大学软件学03级02班 周银辉
一, 效果
二 关于C#读取字符点阵的代码
      (原理就不再阐述了,到Baidu里面搜一下,很多,不过一般都是C/C++的)
      (说明:对于一个字符,GetWordLattics函数返回的bool[,]表示一个16*8或16*16点阵,对应值为true表示该点应该被点亮)
 using System;
using System; using System.Collections.Generic;
using System.Collections.Generic; using System.Text;
using System.Text; using System.IO;
using System.IO; using System.Windows.Forms;
using System.Windows.Forms;
 namespace ShowWord
namespace ShowWord {
{ /// <summary>
    /// <summary> /// 字符解析器
    /// 字符解析器 /// </summary>
    /// </summary> public class WordPaser
    public class WordPaser {
    { private static byte[] bytesOfASC;
        private static byte[] bytesOfASC; private static byte[] bytesOfHanZi;
        private static byte[] bytesOfHanZi; private static string pathOfASC = Application.StartupPath + Path.DirectorySeparatorChar + "ASC16";
        private static string pathOfASC = Application.StartupPath + Path.DirectorySeparatorChar + "ASC16"; private static string pathOfHanZi = Application.StartupPath + Path.DirectorySeparatorChar + "HZK16";
        private static string pathOfHanZi = Application.StartupPath + Path.DirectorySeparatorChar + "HZK16";
 static WordPaser()
        static WordPaser() {
        { try
            try {
            { bytesOfASC = File.ReadAllBytes(pathOfASC);
                bytesOfASC = File.ReadAllBytes(pathOfASC); bytesOfHanZi = File.ReadAllBytes(pathOfHanZi);
                bytesOfHanZi = File.ReadAllBytes(pathOfHanZi); }
            } catch (Exception ex)
            catch (Exception ex) {
            { MessageBox.Show(ex.Message);
                MessageBox.Show(ex.Message); }
            } }
        }
 /// <summary>
        /// <summary> /// 获取指定的字符的点阵
        /// 获取指定的字符的点阵 /// </summary>
        /// </summary> /// <param name="c">字符</param>
        /// <param name="c">字符</param> /// <param name="lines">点阵行数</param>
        /// <param name="lines">点阵行数</param> /// <param name="columns">点阵列数</param>
        /// <param name="columns">点阵列数</param> /// <returns>点阵数据,对应值为true表示该点应该被显示,否则对应点不应该被显示</returns>
        /// <returns>点阵数据,对应值为true表示该点应该被显示,否则对应点不应该被显示</returns> public static bool[,] GetWordLattics(Char c, out int lines,out int columns)
        public static bool[,] GetWordLattics(Char c, out int lines,out int columns) {
        { lines = 16;
            lines = 16; columns = 8;
            columns = 8; bool[,] lattics = new bool[lines, columns];
            bool[,] lattics = new bool[lines, columns];
 int intValue = (int)c;
            int intValue = (int)c; long offset = 0;
            long offset = 0;
 if (intValue <= 255)
            if (intValue <= 255) {
            { offset = intValue * 16L;
                offset = intValue * 16L; for (int i = 0; i < lines; i++)
                for (int i = 0; i < lines; i++) {
                { for (int j = 0; j < columns; j++)
                    for (int j = 0; j < columns; j++) {
                    { byte byteValue = bytesOfASC[offset + i];
                        byte byteValue = bytesOfASC[offset + i]; lattics[i, j] = ((byteValue >> (7 - j)) & 0x1) != 0;
                        lattics[i, j] = ((byteValue >> (7 - j)) & 0x1) != 0; }
                    } }
                }
 }
            } else
            else {
            { lines = 16;
                lines = 16; columns = 16;
                columns = 16; lattics = new bool[lines, columns];
                lattics = new bool[lines, columns];
 byte[] bytes = System.Text.Encoding.GetEncoding("gb2312").GetBytes(c.ToString());
                byte[] bytes = System.Text.Encoding.GetEncoding("gb2312").GetBytes(c.ToString());

 int zone = bytes[0];//刚好是“区”的值,机内码
                int zone = bytes[0];//刚好是“区”的值,机内码    int num = bytes[1];//刚即时“位”的值 ,机内码
                int num = bytes[1];//刚即时“位”的值 ,机内码   
 int area = (zone & 0x00ff) - 0xa0;  //根据机内码取得区码
                int area = (zone & 0x00ff) - 0xa0;  //根据机内码取得区码 int bit = (num & 0x00ff) - 0xa0;   //根据机内码取得位码
                int bit = (num & 0x00ff) - 0xa0;   //根据机内码取得位码
 offset = (94 * (area - 1) + (bit - 1)) * 32L;
                offset = (94 * (area - 1) + (bit - 1)) * 32L; 
                 for (int i = 0; i < lines; i++)
                for (int i = 0; i < lines; i++) {
                { for (int j = 0; j < 2; j++)
                    for (int j = 0; j < 2; j++) {
                    { for (int k = 0; k < 8; k++)
                        for (int k = 0; k < 8; k++) {
                        { byte byteValue = bytesOfHanZi[offset + i * 2 + j];
                            byte byteValue = bytesOfHanZi[offset + i * 2 + j]; lattics[i,8 * j + k] = ((byteValue >> (7 - k)) & 0x1) != 0;
                            lattics[i,8 * j + k] = ((byteValue >> (7 - k)) & 0x1) != 0; }
                        } }
                    } }
                }
 
                }
            }

 return lattics;
            return lattics; }
        } 
     }
    } }
}
3 字库文件下载
代码中用到的两个字库文件(或者你可以在TurboC安装目录下中找到他们) https://files.cnblogs.com/zhouyinhui/zk.rar
 
                    
                

 
     
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号