您的位置:首页 > 其它

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

2006-08-24 22:33 1051 查看
提取16X16汉字字库用于LCD显示
Lanno Cheeke 2006-8-24
使用文件:
UCDOS中的HZK16字模文件
原理:
获取汉字的区位码(又称GB码),在HZK16中算出此汉字的起始地址,以16x2数组方式保存,数组中的值为1则打印,否则为空。
程序说明:
所使用的文字为一级汉字。
双击:位码增一;右击:区码增一。

CHZKView.h

private:

int jj;//位码

int ii;//区码

FILE* pFile;//字库文件指针

CHZKView.cpp

//初始化操作

CHZKView::CHZKView()

{

// TODO: add construction code here

this->pFile = fopen("HZK16","r");

ii = 16;

jj = 1;

}

//输出

void CHZKView::OnDraw(CDC* pDC)

{

CHZKDoc* pDoc = GetDocument();

ASSERT_VALID(pDoc);

CRect rt;

GetClientRect(&rt);

int cx = rt.Width() / 16;

int cy = rt.Height() / 16;

unsigned char pHz[] = "对";

int i = pHz[0] -0xA0;

int j = pHz[1] - 0xA0;

fseek(pFile,(94*(i-1)+(j-1))*32l,SEEK_SET);

unsigned char mat[16][2];

int k = 0;

fread(mat,32,1,pFile);

jj++;

fseek(pFile,(94*(ii-1)+(jj-1))*32l,SEEK_SET);

fread(mat,32,1,pFile);

for(j=0;j<16;j++)

for(i=0;i<2;i++)

for(k=0;k<8;k++)

if(mat[j][i]&(0x80>>k)){

pDC->SetPixel(i*8+k,j,RGB(255,0,0));

pDC->Rectangle((i*8 + k)*cx,j*cy,(i*8 + k)*cx + cx,j*cy + cy);

}

}

//清理操作

CHZKView::~CHZKView()

{

fclose(this->pFile);

}

//区码增一

void CHZKView::OnRButtonUp(UINT nFlags, CPoint point)

{

// TODO: Add your message handler code here and/or call default

ii++;

Invalidate();

CView::OnRButtonUp(nFlags, point);

}

void CHZKView::OnLButtonDblClk(UINT nFlags, CPoint point)

{

// TODO: Add your message handler code here and/or call default

Invalidate();

CView::OnLButtonDblClk(nFlags, point);

}

//输出
void CHZKView::OnDraw(CDC* pDC)

{

CHZKDoc* pDoc = GetDocument();

ASSERT_VALID(pDoc);

CRect rt;

GetClientRect(&rt);

int cx = rt.Width() / 16;

int cy = rt.Height() / 16;

unsigned char pHz[] = "对";

int i = pHz[0] -0xA0;

int j = pHz[1] - 0xA0;

fseek(pFile,(94*(i-1)+(j-1))*32l,SEEK_SET);

unsigned char mat[16][2];

int k = 0;

fread(mat,32,1,pFile);

jj++;

fseek(pFile,(94*(ii-1)+(jj-1))*32l,SEEK_SET);

fread(mat,32,1,pFile);

for(j=0;j<16;j++)

for(i=0;i<2;i++)

for(k=0;k<8;k++)

if(mat[j][i]&(0x80>>k)){

pDC->SetPixel(i*8+k,j,RGB(255,0,0));

pDC->Rectangle((i*8 + k)*cx,j*cy,(i*8 + k)*cx + cx,j*cy + cy);

}

}

//清理操作

CHZKView::~CHZKView()

{

fclose(this->pFile);

}

//区码增一

void CHZKView::OnRButtonUp(UINT nFlags, CPoint point)

{

// TODO: Add your message handler code here and/or call default

ii++;

Invalidate();

CView::OnRButtonUp(nFlags, point);

}

void CHZKView::OnLButtonDblClk(UINT nFlags, CPoint point)

{

// TODO: Add your message handler code here and/or call default

Invalidate();

CView::OnLButtonDblClk(nFlags, point);

}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: