首先,研究了很久,以为和16x16没多大区别,后来又发现了很多24x24需要注意的点,如
不要小看这个按列扫描,如果是16x16的话,可以直接用三层加判断打印出来,如下
for (i = 0; i<16; i++) {
for (j = 0; j<2; j++) {
for (k = 0;k<8; k++) {
flag = buffer[i * 2 + j] & key[k];
printf("%s", flag ? "●" : "○");
}
}
printf("\n");
}
但是24的按列扫描,三层循环判断时是判断的第i行那一列的信息,如果你直接打印的话,屏幕是横着排的,就会造成打出来的是反着得字,如
自从知道列扫描后就换了个方法,不能直接打印那就先存起来吧
bool hanzi[24][24];
完整代码在下面:24x24
#include
int main(void)
{
FILE* fphzk = NULL; unsigned char qh, wh;
int i, j, k; unsigned long offset;
bool hanzi[24][24];
unsigned char buffer[72];
unsigned char word[3] = "我";
qh = word[0] - 0xaf; /*计算区码*/
wh = word[1] - 0xa0;
fphzk = fopen("HZKf2424.hz", "rb");
if (fphzk == NULL) {
fprintf(stderr, "error hzk24\n");
return 1;
}
offset = (94 * (qh - 1) + (wh - 1)) * 72L;
fseek(fphzk, offset, SEEK_SET);
fread(buffer, 1, 72, fphzk);
printf("\n");
for (i = 0; i<24; i++) {
for (j = 0; j<3; j++) {
for (k = 0;k<8; k++) {
if (buffer[i * 3 + j] & (0x80 >> k)) {
hanzi[j * 8 + k][i] =true ;
}else
hanzi[j * 8 + k][i] =false ;
}
}
}
for (i = 0; i < 24; i++) {
for (j = 0; j < 24; j++) {
if(hanzi[i][j])
printf("●");
else
printf("○");
}
printf("\n");
}
fclose(fphzk);
fphzk = NULL;
return 0;
}
代码16x16:
#include
int main(void)
{
FILE* fphzk = NULL;
int i, j, k, offset;
int flag;
unsigned char buffer[32];
unsigned char word[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;
}
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<32; k++) {
printf("%02X ", buffer[k]);
}
printf("\n");
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");
}
fclose(fphzk);
fphzk = NULL;
return 0;
}
24x24出来的结果:
其它说明:
关于汉字点阵字库的原理请参考网上资源,如:https://blog.csdn.net/l_yangliu/article/details/7261759
点阵字库文件在这里下载:https://download.csdn.net/download/hydmonster/10380110