C language asterisk Chinese name

The use of HZK16 Chinese character 16*16 dot matrix font library and sample program-accompany her to wandering (twofei.com)

Refer to the above code, you need the next HZK16 dot matrix library, download link:

pengfexue2/printPlay: Python print 点阵字/ Python print to form Chinese characters (github.com)

 

In the development environment CodeBlocks, put the good HZK16 dot matrix library in the main.c directory at the same level.

│  first_c.cbp
│  first_c.depend
│  first_c.layout
│  HZK16
│  main.c
│  
├─bin
│  └─Debug
│          first_c.exe
│          
└─obj
    └─Debug
            main.o

 

The specific code is as follows, the code of direct copy has been slightly modified:

#include <stdio.h>

int main(void)
{
    FILE* fphzk = NULL;
    FILE* fphzk2 = NULL;
    FILE* fphzk3 = NULL;

    int i, j, k, offset, offset2, offset3;
    int flag, flag2, flag3;

    unsigned char buffer[32];
    unsigned char buffer2[32];
    unsigned char buffer3[32];

    unsigned char word[3] = "长";
    unsigned char word2[3] = "津";
    unsigned char word3[3] = "湖";

    unsigned char key[8] = {
        0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01
    };

    fphzk = fopen("hzk16", "rb");
    if(fphzk == NULL){
        fprintf(stderr, "error hzk16\n");
        return 1;
    }

    fphzk2 = fopen("hzk16", "rb");
    if(fphzk2 == NULL){
        fprintf(stderr, "error hzk16\n");
        return 1;
    }

    fphzk3 = fopen("hzk16", "rb");
    if(fphzk2 == NULL){
        fprintf(stderr, "error hzk16\n");
        return 1;
    }

    offset = (94*(unsigned int)(word[0]-0xa0-1)+(word[1]-0xa0-1))*32;
    fseek(fphzk, offset, SEEK_SET);
    fread(buffer, 1, 32, fphzk);

    offset2 = (94*(unsigned int)(word2[0]-0xa0-1)+(word2[1]-0xa0-1))*32;
    fseek(fphzk2, offset2, SEEK_SET);
    fread(buffer2, 1, 32, fphzk2);

    offset3 = (94*(unsigned int)(word3[0]-0xa0-1)+(word3[1]-0xa0-1))*32;
    fseek(fphzk3, offset3, SEEK_SET);
    fread(buffer3, 1, 32, fphzk3);


    for(k=0; k<16; k++){
        for(j=0; j<2; j++){
            for(i=0; i<8; i++){
                flag = buffer[k*2+j]&key[i];
                printf("%s", flag ? "*" : " ");
            }
        }

        printf("\t");

        for(j=0; j<2; j++){
            for(i=0; i<8; i++){
                flag2 = buffer2[k*2+j]&key[i];
                printf("%s", flag2 ? "*" : " ");
            }
        }

        printf("\t");

        for(j=0; j<2; j++){
            for(i=0; i<8; i++){
                flag3 = buffer3[k*2+j]&key[i];
                printf("%s", flag3 ? "*" : " ");
            }
        }

        printf("\n");
    }

    fclose(fphzk);
    fclose(fphzk2);
    fclose(fphzk3);

    fphzk = NULL;
    fphzk2 = NULL;
    fphzk3 = NULL;
    return 0;
}

 

 

another

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    FILE* fphzk = NULL;
    int i, j, k, offset;
    int flag;

    unsigned char buffer[32];
    unsigned char word[5];

    unsigned char key[8] = {
        0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01
    };

    fphzk = fopen("hzk16", "rb");

    if(fphzk == NULL){
        fprintf(stderr, "error hzk16\n");
        return 1;
    }

    while(1){
        printf("输入要生成字模的汉字(多个):");

        for(;;){
            fgets((char*)word, 3, stdin);

            if(*word == '\n')
                break;

            offset = (94*(unsigned int)(word[0]-0xa0-1)+(word[1]-0xa0-1))*32;

            fseek(fphzk, offset, SEEK_SET);
            fread(buffer, 1, 32, fphzk);

            for(k=0; k<16; k++){
                for(j=0; j<2; j++){
                    for(i=0; i<8; i++){

                        flag = buffer[k*2+j]&key[i];
                        printf("%s", flag ? "*" : " ");
                    }
                }
                printf("\n");
            }
            printf("\n");
        }
    }

    fclose(fphzk);
    fphzk = NULL;

    return 0;
}

 

There is another

C language advanced programming example: [1] Dot matrix Chinese characters-Baidu experience (baidu.com)

 

The enlargement of the characters seems easy to achieve, but the reduction is a bit problematic. Is it the use of C language graphics programming?

Guess you like

Origin blog.csdn.net/sdaujz/article/details/110085592