字符的点阵显示(模拟户外广告显示屏)

                       字符的点阵显示
 
                                                 电子科技大学软件学03级02班 周银辉


一, 效果
LCD.PNG

二 关于C#读取字符点阵的代码
      (原理就不再阐述了,到Baidu里面搜一下,很多,不过一般都是C/C++的)
      (说明:对于一个字符,GetWordLattics函数返回的bool[,]表示一个16*8或16*16点阵,对应值为true表示该点应该被点亮)

 

using  System;
using  System.Collections.Generic;
using  System.Text;
using  System.IO;
using  System.Windows.Forms;

namespace  ShowWord
{
    
/// <summary>
    
/// 字符解析器
    
/// </summary>

    public class WordPaser
    
{
        
private static byte[] bytesOfASC;
        
private static byte[] bytesOfHanZi;
        
private static string pathOfASC = Application.StartupPath + Path.DirectorySeparatorChar + "ASC16";
        
private static string pathOfHanZi = Application.StartupPath + Path.DirectorySeparatorChar + "HZK16";

        
static WordPaser()
        
{
            
try
            
{
                bytesOfASC 
= File.ReadAllBytes(pathOfASC);
                bytesOfHanZi 
= File.ReadAllBytes(pathOfHanZi);
            }

            
catch (Exception ex)
            
{
                MessageBox.Show(ex.Message);
            }

        }


        
/// <summary>
        
/// 获取指定的字符的点阵
        
/// </summary>
        
/// <param name="c">字符</param>
        
/// <param name="lines">点阵行数</param>
        
/// <param name="columns">点阵列数</param>
        
/// <returns>点阵数据,对应值为true表示该点应该被显示,否则对应点不应该被显示</returns>

        public static bool[,] GetWordLattics(Char c, out int lines,out int columns)
        
{
            lines 
= 16;
            columns 
= 8;
            
bool[,] lattics = new bool[lines, columns];

            
int intValue = (int)c;
            
long offset = 0;

            
if (intValue <= 255)
            
{
                offset 
= intValue * 16L;
                
for (int i = 0; i < lines; i++)
                
{
                    
for (int j = 0; j < columns; j++)
                    
{
                        
byte byteValue = bytesOfASC[offset + i];
                        lattics[i, j] 
= ((byteValue >> (7 - j)) & 0x1!= 0;
                    }

                }


            }

            
else
            
{
                lines 
= 16;
                columns 
= 16;
                lattics 
= new bool[lines, columns];

                
byte[] bytes = System.Text.Encoding.GetEncoding("gb2312").GetBytes(c.ToString());


                
int zone = bytes[0];//刚好是“区”的值,机内码   
                int num = bytes[1];//刚即时“位”的值 ,机内码   

                
int area = (zone & 0x00ff- 0xa0;  //根据机内码取得区码
                int bit = (num & 0x00ff- 0xa0;   //根据机内码取得位码

                offset 
= (94 * (area - 1+ (bit - 1)) * 32L;
                
                
for (int i = 0; i < lines; i++)
                
{
                    
for (int j = 0; j < 2; j++)
                    
{
                        
for (int k = 0; k < 8; k++)
                        
{
                            
byte byteValue = bytesOfHanZi[offset + i * 2 + j];
                            lattics[i,
8 * j + k] = ((byteValue >> (7 - k)) & 0x1!= 0;
                        }

                    }

                }


               
            }



            
return lattics;
        }

    
    }

}

 


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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值