Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2275812
  • 博文数量: 668
  • 博客积分: 10016
  • 博客等级: 上将
  • 技术积分: 8588
  • 用 户 组: 普通用户
  • 注册时间: 2008-05-29 19:22
文章分类

全部博文(668)

文章存档

2011年(1)

2010年(2)

2009年(273)

2008年(392)

分类:

2008-08-09 08:20:54

在论坛里是不是常看到有网友灌的那些用字符组成文字的帖子
下面我就基础写了一道用C语言调用字体库实现以上功能的程序
最终生成的字符文字保存在运行目录下的“美丽的汉字.txt”文件中

/*
*字符组成的汉字程序
*LO几又VE 12:34 2005-5-24
*TC:将hzk16文件放至安装目录下 VC:将hzk16文件放至运行目录下
*hzk16文件下载地址:
*
*/

#include
#include

int priChi(unsigned char *); /*中文打印函数,传入参数:中文数组指针 返回值 -1 异常 0 正常*/

int main()
{
    unsigned char chinese[]="字符组成的汉字";

    if(-1 == priChi(chinese))
    { /*打印或者保存异常*/
        printf("Press any key to exit...");
        fflush(stdin);
        getch();
        return 1;
    }
    return 0;
}

int priChi(unsigned char *chi)
{
    unsigned char mat[16][2];
    char write[5],space[5];
    int i,j,k;
    int sec,pot;
    FILE *HZK, *fp;

    if((HZK=fopen("hzk16","rb")) == NULL) /*打开字体库文件*/
    {
        printf("Open style file (hzk16) failed!\n");
        return -1;
    }

    if((fp=fopen("美丽的汉字.txt","w")) == NULL) /*打开汉字保存文件*/
    {
        printf("Open file failed!\n");
        return -1;
    }

    printf("Input the write chars:");
    gets(write);
    printf("Input the space chars:");
    gets(space);

    while(*chi)
    {
        sec = *chi-0xa0; /*获得区码*/
        pot = *(chi+1)-0xa0; /*获得位码*/
        fseek(HZK,(94*(sec-1)+(pot-1))*32l,SEEK_SET);
        fread(mat,32,1,HZK);

        for(j=0; j < 16; j++,printf("\n"),fprintf(fp,"\n"))
            for(i=0; i < 2; i++)
                for(k=0; k < 8; k++)
                {
                    if(mat[j][i] & (0x80 >> k))
                    {/*“笔迹”*/
                        printf("%s",write);
                        fprintf(fp,"%s",write);
                    }
                    else
                    {/*“空白”*/
                        printf("%s",space);
                        fprintf(fp,"%s",space);
                    }
                }
        
        chi += 2; /*指针指向下一中文字符*/
        printf("Press any key to print the next word...\n");
        getch();
    }
    getch();
    fclose(HZK);
    fclose(fp);
    return 0;
}

/*
测试:
输入:
OO
--
输出:
------------OO------------------
--------------OO----------------
----OOOOOOOOOOOOOOOOOOOOOOOO----
----OO--------------------OO----
--OO--------------------OO------
------OOOOOOOOOOOOOOOO----------
------------------OO------------
----------------OO--------------
--------------OO----------OO----
OOOOOOOOOOOOOOOOOOOOOOOOOOOOOO--
--------------OO----------------
--------------OO----------------
--------------OO----------------
--------------OO----------------
----------OO--OO----------------
------------OO------------------
------OO----------OO------------
------OO----OO----OO------OO----
------OOOOOOOOOO--OOOOOOOOOOOO--
----OO--OO------OO--OO----------
--OO------OO--OO------OO--------
OO------OO------------OO--------
--------OO------------OO--OO----
------OO--OOOOOOOOOOOOOOOOOOOO--
----OOOO--------------OO--------
--OO--OO----OO--------OO--------
OO----OO------OO------OO--------
------OO------OO------OO--------
------OO--------------OO--------
------OO--------------OO--------
------OO----------OO--OO--------
------OO------------OO----------
------OO------------------------
------OO----------------OO------
----OO--------OOOOOOOOOOOOOO----
----OO--------OO--------OO------
--OO------OO--OO--------OO------
OOOOOOOOOO----OO--------OO------
------OO------OOOOOOOOOOOO------
----OO--------OO--------OO------
--OO----------OO--------OO------
OOOOOOOOOOOO--OO--------OO------
--OO----------OOOOOOOOOOOO------
--------------OO--------OO------
------OOOOOO--OO--------OO------
OOOOOO--------OO--------OO------
--OO------OOOOOOOOOOOOOOOOOOOO--
--------------------------------
----------------OO--------------
----------------OO--OO----------
----------------OO----OO--------
----OOOOOOOOOOOOOOOOOOOOOOOO----
----OO----------OO--------------
----OO----------OO--------------
----OO----------OO--------OO----
----OOOOOOOOOO----OO------OO----
----OO------OO----OO----OO------
----OO------OO----OO----OO------
----OO------OO------OOOO--------
----OO--OO--OO------OO----------
----OO----OO------OOOO------OO--
--OO------------OO----OO----OO--
OO------------OO--------OO--OO--
--------------------------OOOO--
------OO----------OO------------
------OO----------OO------------
----OO------OO----OO------OO----
--OOOOOOOOOOOOOO--OOOOOOOOOOOO--
--OO--------OO--OO--------OO----
--OO--------OOOO----------OO----
--OO--------OO------------OO----
--OO--------OO--OO--------OO----
--OOOOOOOOOOOO----OOOO----OO----
--OO--------OO------OO----OO----
--OO--------OO------------OO----
--OO--------OO------------OO----
--OO--------OO------------OO----
--OOOOOOOOOOOO------------OO----
--OO--------OO------OO--OO------
----------------------OO--------
--------------------------------
--OO--------------------OO------
----OOOO--OOOOOOOOOOOOOOOOOO----
------OO----------------OO------
OO----------OO----------OO------
--OOOO------OO----------OO------
----OO------OO--------OO--------
--------OO----OO------OO--------
------OO------OO----OO----------
----OO----------OO--OO----------
OOOOOO------------OO------------
----OO----------OO--OO----------
----OO--------OO------OO--------
----OO------OO----------OO------
----OO----OO------------OOOOOO--
--------OO----------------OO----
------------OO------------------
--------------OO----------------
----OOOOOOOOOOOOOOOOOOOOOOOO----
----OO--------------------OO----
--OO--------------------OO------
------OOOOOOOOOOOOOOOO----------
------------------OO------------
----------------OO--------------
--------------OO----------OO----
OOOOOOOOOOOOOOOOOOOOOOOOOOOOOO--
--------------OO----------------
--------------OO----------------
--------------OO----------------
--------------OO----------------
----------OO--OO----------------
------------OO------------------
*/

怎么样?很酷吧!
高级应用:将space以及write改为字符串常量 并给其赋值为中文字符就可以实现更酷的特效了
如:
write[] = "酷";
space[] = "  ";//注意空格宽度与write的匹配
效果:
            酷                  
              酷                
    酷酷酷酷酷酷酷酷酷酷酷酷    
    酷                    酷    
  酷                    酷      
      酷酷酷酷酷酷酷酷          
                  酷            
                酷              
              酷          酷    
酷酷酷酷酷酷酷酷酷酷酷酷酷酷酷  
              酷                
              酷                
              酷                
              酷                
          酷  酷                
            酷                  
      酷          酷            
      酷    酷    酷      酷    
      酷酷酷酷酷  酷酷酷酷酷酷  
    酷  酷      酷  酷          
  酷      酷  酷      酷        
酷      酷            酷        
        酷            酷  酷    
      酷  酷酷酷酷酷酷酷酷酷酷  
    酷酷              酷        
  酷  酷    酷        酷        
酷    酷      酷      酷        
      酷      酷      酷        
      酷              酷        
      酷              酷        
      酷          酷  酷        
      酷            酷          
      酷                        
      酷                酷      
    酷        酷酷酷酷酷酷酷    
    酷        酷        酷      
  酷      酷  酷        酷      
酷酷酷酷酷    酷        酷      
      酷      酷酷酷酷酷酷      
    酷        酷        酷      
  酷          酷        酷      
酷酷酷酷酷酷  酷        酷      
  酷          酷酷酷酷酷酷      
              酷        酷      
      酷酷酷  酷        酷      
酷酷酷        酷        酷      
  酷      酷酷酷酷酷酷酷酷酷酷  
                                
                酷              
                酷  酷          
                酷    酷        
    酷酷酷酷酷酷酷酷酷酷酷酷    
    酷          酷              
    酷          酷              
    酷          酷        酷    
    酷酷酷酷酷    酷      酷    
    酷      酷    酷    酷      
    酷      酷    酷    酷      
    酷      酷      酷酷        
    酷  酷  酷      酷          
    酷    酷      酷酷      酷  
  酷            酷    酷    酷  
酷            酷        酷  酷  
                          酷酷  
      酷          酷            
      酷          酷            
    酷      酷    酷      酷    
  酷酷酷酷酷酷酷  酷酷酷酷酷酷  
  酷        酷  酷        酷    
  酷        酷酷          酷    
  酷        酷            酷    
  酷        酷  酷        酷    
  酷酷酷酷酷酷    酷酷    酷    
  酷        酷      酷    酷    
  酷        酷            酷    
  酷        酷            酷    
  酷        酷            酷    
  酷酷酷酷酷酷            酷    
  酷        酷      酷  酷      
                      酷        
                                
  酷                    酷      
    酷酷  酷酷酷酷酷酷酷酷酷    
      酷                酷      
酷          酷          酷      
  酷酷      酷          酷      
    酷      酷        酷        
        酷    酷      酷        
      酷      酷    酷          
    酷          酷  酷          
酷酷酷            酷            
    酷          酷  酷          
    酷        酷      酷        
    酷      酷          酷      
    酷    酷            酷酷酷  
        酷                酷    
            酷                  
              酷                
    酷酷酷酷酷酷酷酷酷酷酷酷    
    酷                    酷    
  酷                    酷      
      酷酷酷酷酷酷酷酷          
                  酷            
                酷              
              酷          酷    
酷酷酷酷酷酷酷酷酷酷酷酷酷酷酷  
              酷                
              酷                
              酷                
              酷                
          酷  酷                
            酷                  

将替换字符改为QQ里的转义图符 就可以cool一把咯[呵呵 n张狂笑~~~~`````一个大大的晕]
                             
                                                          
                             
                                                          
                             
                                                                
         
                                                       
                      
                                                             
                                                          
                             
                                                             
             
                                                             
                               
当然 你还可以装载其他字体库来打印更好看更细腻的汉字,这里就不再展开了。

阅读(938) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~