用C显汉字方法有很多。
这里用到了比较普遍的汉字库取字模显示汉字;
- int getbit(unsigned char c, int n)
- {
- return((c>>n) & 1);
- }
- void outtextex(char *text, int x, int y, int color)
- {
- FILE* fp;
- int i, j;
- int ox = x;
- unsigned char ch, cl, buf[32];
- long pos;
- if((fp = fopen("HZK16", "rb")) == NULL ) return;
- while(*text != NULL)
- {
- if(*text == '#')
- {
- y += 16;
- x = ox;
- text ++;
- continue;
- }
- ch = *text;
- cl = *(text + 1);
- pos = 32 * ((ch - 0xa1) * 94L + cl - 0xa1);
- fseek(fp, pos, SEEK_SET);
- fread(buf, 1, 32, fp);
- for(i = 0; i<16; i++)
- for(j = 0; j<8; j++)
- {
- if(getbit(buf[2*i], 7-j))
- {
- putpixel(x+j, y+i, color);
- }
- if(getbit(buf[2*i+1], 7-j))
- {
- putpixel(x+j+8, y+i, color);
- }
- }
- text += 2;
- x += 16;
- }
- fclose(fp);
- }
"#"号为分行作用!