// 字阵列显示测试.cpp : 通过字库随意显示文字点阵列(已验证)
//
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main()
{
FILE* fd = NULL;
int i, j, k, offset;
int flag;
unsigned char buffer[32];
unsigned char word[4] = "大";
unsigned char key[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };
fd = fopen("hzk16s", "rb");//hzk16是字库文件名,默认路径在本程序同一文件夹
if (fd == NULL)
{
fprintf(stderr, "error hzk16\n");
return 1;
}
offset = (94 * (unsigned int)(word[0] - 0xa0 - 1) + (word[1] - 0xa0 - 1)) * 32;//汉字在字库中的绝对偏移地址,乘以32是因为每个字符占32字节
fseek(fd, offset, SEEK_SET); //在字模中找到相应汉字对应的字模数据位置 //将位置指针移动到文件开头。
fread(buffer, 1, 32, fd); //从字模文件中读取数据
for (k = 0; k < 32; k++) {
printf("%02X ", buffer[k]);
}
printf("\n");
for (k = 0; k < 16; k++) //输出:16行,每行两个字节,每个字节8个二进制数,所以为16*16
{
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(fd);
fd = NULL;
return 0;
}
VS C++控制台运行结果
字库 链接:https://pan.baidu.com/s/1KtncRDQ1v9dNvS2dAqel1A?pwd=qbt1
提取码:qbt1