提取汉字字库文件里面二进制数据转换为十六进制数据存到文件

在写打印机程序的时候,需要将汉字字库文件(.hz或者.zf文件)里面二进制数据提取出来放到Flash里面,我当时采用的是16进制的无符号16位数组存储,因为字库涉及版权问题,就不予以上传,下面是C++实现源码:

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string.h>

using namespace std;

#define HZ_NUM 3755
#define HZ_HEIGHT  16
#define HZ_WIDTH 16

#define LINE_NUM  HZ_HEIGHT*HZ_WIDTH/8

int main()
{
    FILE *input;
    FILE *output;
    unsigned char temp;
    char high,low;
    int i=0;


    if((input = fopen("font.hz","rb")) == NULL || (output = fopen("font.rtf","w")) == NULL)
    {
        return -1;
    }


    temp = fgetc(input);
    while(!feof(input) && i<(HZ_NUM*LINE_NUM))
    {
        low = temp & 0x0F;
        high = temp >> 4;
        if(i%2==0)
            fprintf(output,"0x%x%x",high,low);
        else
            fprintf(output,"%x%x,",high,low);
        temp = fgetc(input);
        i++;
        if(i%2==0)
            fprintf(output," ");
        if(i%LINE_NUM==0)
            fprintf(output,"\n");
    }
    printf("二进制文件成功转化位十六进制文件");
    fclose(input);
    fclose(output);


    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值