咨询电话:010-82823766

显示12*12点阵汉字的示例
  • 2008-11-25 10:10:00
  • 发表时间:
  • 浏览次数:
  • 网络
  • 文章来源:
  • 佚名
  • 作者:

说明:

  此程序为显示12*12点阵汉字的示例,需要使用 HZK12 文件。你也可以直接在你所编写的任何 C 语言程序中包含 void hanzi12(int x,int y,char *s,int colour) 函数,来显示所需要的汉字信息!

  注意:不能通过此函数来显示英文信息,更不能通过此函数来达到中英文的混合显示!

程序源码:

#include<stdio.h>
#include<graphics.h>

/* 显示12*12点阵汉字函数,使用HZK12文件,x,y为显示坐标,s为显示字符串,colour为颜色 */
void hanzi12(int x,int y,char *s,int colour){
   FILE *fp;
   char buffer[24];
   register i,j,k;
   unsigned char qh,wh;
   unsigned long location;
   if((fp=fopen("hzk12","rb"))==NULL){
      printf("Can't open hzk12!");
      getch();
   }
   while(*s){
      qh=*(s)-0xa0;
      wh=*(s+1)-0xa0;
      location=(94*(qh-1)+(wh-1))*24L;
      fseek(fp,location,SEEK_SET);
      fread(buffer,24,1,fp);
      for(i=0;i<12;i++)
         for(j=0;j<2;j++)
            for(k=0;k<8;k++)
               if((buffer[i*2+j]>>(7-k))&0x1)
                  putpixel(x+8*j+k,y+i,colour);
      s+=2;
      x+=12;
   }
   fclose(fp);
}

main(){
   int gd=DETECT,gm;
   initgraph(&gd,&gm,"");

   hanzi12(240,160,"威龙网C语言显示汉字示例!",LIGHTCYAN);

   getch();
   closegraph();

top
推荐导读
推荐导读
bottom
top
热门文章
热门文章
bottom