要下载HZK16字体库
代码
#include#include #include #include #include #include using namespace std; void gotoxy(int x,int y) // 将光标移动到指定坐标 { COORD pos = {x,y}; HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleCursorPosition(hOut,pos); } void color(int x) // 给文字上色 { if(x >= 0 && x <= 15) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),x); else SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7); } int main() { FILE* zk = NULL; int offset, flag, cnt = 1; unsigned char buffer[32]; unsigned char word[5]; unsigned char key[8] = {0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01}; zk = fopen("HZK16","rb"); // 打开字库 if(zk == NULL) cout << "字库打开失败" << endl; while(1) { fgets((char*) word, 3, stdin); if(*word == '\n') break; // 计算汉字在HZK16中的绝对偏移位置 offset = (94*(unsigned int)(word[0]-0xa0-1)+(word[1]-0xa0-1))*32; fseek(zk, offset, SEEK_SET); fread(buffer, 1, 32, zk); system("cls"); if(cnt % 15 == 0) // 0为黑色所以不要 cnt++; color(cnt % 15); for(int i = 0; i < 16; i++) // 打印汉字的每个点 { for(int j = 0; j < 2; j++) { for(int k = 0; k < 8; k++) { flag = buffer[i * 2 + j] & key[k]; printf("%s", flag ? "■": " "); } } cout << endl; } Sleep(888); cnt++; } color(7); }
Comments | NOTHING