Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7555014
  • 博文数量: 961
  • 博客积分: 15795
  • 博客等级: 上将
  • 技术积分: 16612
  • 用 户 组: 普通用户
  • 注册时间: 2010-08-07 14:23
文章分类

全部博文(961)

文章存档

2016年(1)

2015年(61)

2014年(41)

2013年(51)

2012年(235)

2011年(391)

2010年(181)

分类: 嵌入式

2012-09-10 17:40:57


点击(此处)折叠或打开

  1. /*******************************************************************************
  2. ** 程序名称:演示使用HZK16点阵字库的程序
  3. ** 程序描述:使用HZK16实现显示16*16点阵汉字
  4. ** 性能提升:
  5. ** 程序版本:V1.0
  6. ** 程序作者:syrchina
  7. ** 最后修改:2011年8月16日
  8. *******************************************************************************/
  9. #include <stdio.h>
  10.   
  11. /*******************************************************************************
  12. ** 函数名称:Bytes_Read_from_HZK16
  13. ** 函数描述:从字库文件中读取一个汉字的字模点阵数据
  14. ** 入口参数:unsigned char *s 指向目标汉字的指针,
  15.              char* const chs 用于存储字模的数组首地址
  16. ** 出口参数:无
  17. *******************************************************************************/
  18. void Bytes_Read_from_HZK16(unsigned char *s, char* const chs)
  19. {
  20.     FILE *fp;
  21.     unsigned long offset;
  22.       
  23.     offset=((s[0]-0xa1)*94+(s[1]-0xa1))*32; //根据内码找出汉字在HZK16中的偏移位置
  24.       
  25.     if((fp=fopen("HZK16","r"))==NULL) return; //打开字库文件
  26.     fseek(fp,offset,SEEK_SET); //文件指针偏移到要找的汉字处
  27.     fread(chs,32,1,fp); //读取该汉字的字模
  28.     fclose(fp);
  29. }
  30.   
  31. /*******************************************************************************
  32. ** 函数名称:Bytes_Display
  33. ** 函数描述:在屏幕上显示一个汉字
  34. ** 入口参数:char* const chs 存储了汉字点阵数据的数组首地址
  35. ** 出口参数:无
  36. *******************************************************************************/
  37. void Bytes_Display(char* const chs)
  38. {
  39.     int i,j;
  40.       
  41.     for (i=0;i<32;i++)//显示
  42.     {
  43.         if (i%2==0) printf("\n"); //每行两字节,16X16点阵
  44.         for (j=7;j>=0;j--)
  45.         {
  46.             if (chs[i]&(0x1<<j))
  47.                 {printf("O");} //由高到低,为1则输出'O',反之输出'-';
  48.             else
  49.                 {printf("-");}
  50.         }
  51.     }
  52. }
  53.   
  54. /*******************************************************************************
  55. ** 函数名称:main
  56. ** 函数描述:main 函数
  57. ** 入口参数:无
  58. ** 出口参数:无
  59. *******************************************************************************/
  60. int main(void)
  61. {
  62.     char chs[32]; //16*16=256个点
  63.     unsigned char s[]="中国"; //要显示的汉字
  64.       
  65.     Bytes_Read_from_HZK16(&s[0],chs); //去字库中读取汉字字模
  66.     Bytes_Display(chs); //在屏幕上显示这个汉字
  67.     printf("\n");
  68.       
  69.     Bytes_Read_from_HZK16(&s[2],chs); //去字库中读取汉字字模,注意每个汉字占2个char的存储空间
  70.     Bytes_Display(chs); //在屏幕上显示这个汉字
  71.       
  72.     return 0;
  73. }

 HZK16.rar   
阅读(8078) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~