用TC读取字库显示汉字有一段时间直接读取汉字库,以期不用汉字系统也能显示汉字,是很流行的技术,现在也就在工控行业用得上了。这是硬件发展、大肆浪费内存的结果。暂且不论,让我们看看汉字库。 16X16点阵的字库按照内码顺序排列,每个字用32字节(256BIT)存放点阵信息。格式如下:
第一字节第二字节 第三字节第四字节 第五字节第六字节 第七字节第八字节 。 。 。 你看程序吧,很清楚的。 但是,又不是每个字库都一样。可能是因为有些字库把英文字模也放在一起吧。我所用的是UCDOS的字库,长度大概是2xxK,有一段时间我把SPDOS的字库放错地方了,结果出来的都是乱码。 #include < io.h> #include < graphics.h> #include < fcntl.h> #include < dos.h> #define CCLIB "C:\HZK16" display(unsigned char *matrix,int x,int y,int color) { int i,j,y2; for(i=0; i < 16; ++i) { for(j=0; j < 8; ++j) if (matrix[i+i]&(1 < < (7-j))) putpixel(x+j,y,color); for(j = 0; j < 8;++j) if(matrix[i+i+1]&(1 < < (7-j))) putpixel(x+j+8,y,color); y++; } } main() { int col,row,handle; unsigned qh,wh; unsigned long offset; unsigned char *hz,hzm[32]; unsigned char cz[]= "使用PUTPIXEL显示汉字,UCDOS16点阵字库" ; intdriver="DETECT,mode=0;" handle= open(CCLIB,O_RDONLY|O_BINARY); if(handle== -1) { printf("Can't open the cclib!"); exit(-1); } initgraph(&driver,&mode,""); col=130;row=150; hz=cz; while(*hz){ qh=*hz-0xa0; wh=*(hz+1)-0xa0; offset=(94*(qh-1)+(wh-1))*32l; lseek(handle,offset,SEEK_SET); read(handle,hzm,32); display(hzm,col,row,12); col += 16; // Next character. hz += 2; } close(handle); bioskey(0); closegraph(); }下一页还有一个程序,有兴趣可以试试。 |
Copyright 1998-2002 Fadshop.net, Inc. All rights reserved. jhj123@163.net |