提取16X16汉字字库用于LCD显示

提取16X16汉字字库用于LCD显示

Lanno Cheeke 2006-8-24

使用文件:

UCDOS中的HZK16字模文件

原理:

获取汉字的区位码(又称GB码),在HZK16中算出此汉字的起始地址,以16x2数组方式保存,数组中的值为1则打印,否则为空。

程序说明:

所使用的文字为一级汉字。

双击:位码增一;右击:区码增一。

 

  1. CHZKView.h
  2. private:
  3.        int jj;//位码
  4.        int ii;//区码
  5.        FILE* pFile;//字库文件指针
  6. CHZKView.cpp
  7. //初始化操作
  8. CHZKView::CHZKView()
  9. {
  10.        // TODO: add construction code here
  11.        this->pFile = fopen("HZK16","r");
  12.        ii = 16;
  13.        jj = 1;
  14.       
  15. }
  16. //输出
  17. void CHZKView::OnDraw(CDC* pDC)
  18. {
  19.        CHZKDoc* pDoc = GetDocument();
  20.        ASSERT_VALID(pDoc);
  21.        CRect rt;
  22.        GetClientRect(&rt);
  23.       
  24.        int cx = rt.Width() / 16;
  25.        int cy = rt.Height() / 16;
  26.       
  27.        unsigned char pHz[] = "对";
  28.        int i = pHz[0] -0xA0;
  29.        int j = pHz[1] - 0xA0;
  30.        fseek(pFile,(94*(i-1)+(j-1))*32l,SEEK_SET);
  31.        unsigned char mat[16][2];
  32.        int k = 0;
  33.        fread(mat,32,1,pFile);
  34.       
  35.        jj++;
  36.        fseek(pFile,(94*(ii-1)+(jj-1))*32l,SEEK_SET);
  37.        fread(mat,32,1,pFile);
  38.        for(j=0;j<16;j++)
  39.               for(i=0;i<2;i++)
  40.                      for(k=0;k<8;k++)
  41.                             if(mat[j][i]&(0x80>>k)){
  42.                                    pDC->SetPixel(i*8+k,j,RGB(255,0,0));
  43.                                    pDC->Rectangle((i*8 + k)*cx,j*cy,(i*8 + k)*cx + cx,j*cy + cy);
  44.                             }                                       
  45.                            
  46. }
  47. //清理操作
  48. CHZKView::~CHZKView()
  49. {
  50.        fclose(this->pFile);
  51. }
  52. //区码增一
  53. void CHZKView::OnRButtonUp(UINT nFlags, CPoint point)
  54. {
  55.        // TODO: Add your message handler code here and/or call default
  56.        ii++;
  57.        Invalidate();
  58.        CView::OnRButtonUp(nFlags, point);
  59. }
  60.  
  61. void CHZKView::OnLButtonDblClk(UINT nFlags, CPoint point)
  62. {
  63.        // TODO: Add your message handler code here and/or call default
  64.        Invalidate();
  65.        CView::OnLButtonDblClk(nFlags, point);
  66. }

//输出

  1. void CHZKView::OnDraw(CDC* pDC)
  2. {
  3.        CHZKDoc* pDoc = GetDocument();
  4.        ASSERT_VALID(pDoc);
  5.        CRect rt;
  6.        GetClientRect(&rt);
  7.       
  8.        int cx = rt.Width() / 16;
  9.        int cy = rt.Height() / 16;
  10.       
  11.        unsigned char pHz[] = "对";
  12.        int i = pHz[0] -0xA0;
  13.        int j = pHz[1] - 0xA0;
  14.        fseek(pFile,(94*(i-1)+(j-1))*32l,SEEK_SET);
  15.        unsigned char mat[16][2];
  16.        int k = 0;
  17.        fread(mat,32,1,pFile);
  18.       
  19.        jj++;
  20.        fseek(pFile,(94*(ii-1)+(jj-1))*32l,SEEK_SET);
  21.        fread(mat,32,1,pFile);
  22.        for(j=0;j<16;j++)
  23.               for(i=0;i<2;i++)
  24.                      for(k=0;k<8;k++)
  25.                             if(mat[j][i]&(0x80>>k)){
  26.                                    pDC->SetPixel(i*8+k,j,RGB(255,0,0));
  27.                                    pDC->Rectangle((i*8 + k)*cx,j*cy,(i*8 + k)*cx + cx,j*cy + cy);
  28.                             }                                       
  29.                            
  30. }

  1. //清理操作
  2. CHZKView::~CHZKView()
  3. {
  4.        fclose(this->pFile);
  5. }
  6. //区码增一
  7. void CHZKView::OnRButtonUp(UINT nFlags, CPoint point)
  8. {
  9.        // TODO: Add your message handler code here and/or call default
  10.        ii++;
  11.        Invalidate();
  12.        CView::OnRButtonUp(nFlags, point);
  13. }
  14.  
  15. void CHZKView::OnLButtonDblClk(UINT nFlags, CPoint point)
  16. {
  17.        // TODO: Add your message handler code here and/or call default
  18.        Invalidate();
  19.        CView::OnLButtonDblClk(nFlags, point);
  20. }

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值