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

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


一, 效果
LCD.PNG

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

 

None.gif using  System;
None.gif
using  System.Collections.Generic;
None.gif
using  System.Text;
None.gif
using  System.IO;
None.gif
using  System.Windows.Forms;
None.gif
None.gif
namespace  ShowWord
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// 字符解析器
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class WordPaser
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
private static byte[] bytesOfASC;
InBlock.gif        
private static byte[] bytesOfHanZi;
InBlock.gif        
private static string pathOfASC = Application.StartupPath + Path.DirectorySeparatorChar + "ASC16";
InBlock.gif        
private static string pathOfHanZi = Application.StartupPath + Path.DirectorySeparatorChar + "HZK16";
InBlock.gif
InBlock.gif        
static WordPaser()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                bytesOfASC 
= File.ReadAllBytes(pathOfASC);
InBlock.gif                bytesOfHanZi 
= File.ReadAllBytes(pathOfHanZi);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch (Exception ex)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                MessageBox.Show(ex.Message);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

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

InBlock.gif        public static bool[,] GetWordLattics(Char c, out int lines,out int columns)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            lines 
= 16;
InBlock.gif            columns 
= 8;
InBlock.gif            
bool[,] lattics = new bool[lines, columns];
InBlock.gif
InBlock.gif            
int intValue = (int)c;
InBlock.gif            
long offset = 0;
InBlock.gif
InBlock.gif            
if (intValue <= 255)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                offset 
= intValue * 16L;
InBlock.gif                
for (int i = 0; i < lines; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
for (int j = 0; j < columns; j++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        
byte byteValue = bytesOfASC[offset + i];
InBlock.gif                        lattics[i, j] 
= ((byteValue >> (7 - j)) & 0x1!= 0;
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

InBlock.gif
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                lines 
= 16;
InBlock.gif                columns 
= 16;
InBlock.gif                lattics 
= new bool[lines, columns];
InBlock.gif
InBlock.gif                
byte[] bytes = System.Text.Encoding.GetEncoding("gb2312").GetBytes(c.ToString());
InBlock.gif
InBlock.gif
InBlock.gif                
int zone = bytes[0];//刚好是“区”的值,机内码   
InBlock.gif
                int num = bytes[1];//刚即时“位”的值 ,机内码   
InBlock.gif

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

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

ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

InBlock.gif
InBlock.gif               
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif
InBlock.gif            
return lattics;
ExpandedSubBlockEnd.gif        }

InBlock.gif    
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

 


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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值