咨询电话:010-82823766

从自制汉字字库中显示汉字的示例
  • 2008-11-25 10:14:27
  • 发表时间:
  • 浏览次数:
  • 网络
  • 文章来源:
  • 佚名
  • 作者:

程序源码:

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

/* 从自制字库中显示num个汉字,x,y为显示汉字的坐标        */
/* location为汉字在自制字库中的位置,num为显示汉字个数   */
/* f为文件名(也可以不作为参数传递)                       */

void hanzi(int x,int y,int location,int num,int colour,char *f){
  FILE *fp;
  char buffer[32];
  int i,j,k,l,hori,vert;
  if((fp=fopen(f,"rb"))==NULL)
    printf("Can't open file \"%s\"!",f);
  fseek(fp,location*32,SEEK_SET);
  for(l=0;l<num;l++){
    fread(buffer,32,1,fp);
    for(i=0;i<16;i++)
      for(j=0;j<2;j++)
        for(k=0;k<8;k++)
          if(((buffer[i*2+j]>>(7-k))&0x1)!=NULL)
            putpixel(x+8*j+k,y+i,colour);
    x+=16;
  }
  fclose(fp);
}

main(){
  int gd=DETECT,gm;
  initgraph(&gd,&gm,"");
  hanzi(205,205,13,13,BROWN,"myhzk16");
  getch();
  closegraph();
}

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