最近项目中想要在视频中添加OSD ,用来显示时间和产品水印,所以记录下怎么使用字库
关于字库中 汉字怎么提取相关资料可以参考
HZK16 和 ASC16字库用法
而如果要直接查看 GB2312简体中文编码表的话在这里:
GB2312简体中文编码表
字库使用很简单,看完上面的链接就已经可以了,这里直接给出代码了
注意! 在编写代码时候,需要把代码文件格式改为 GB2312
注意! 在编写代码时候,需要把代码文件格式改为 GB2312
注意! 在编写代码时候,需要把代码文件格式改为 GB2312
因为 如果在 utf-8 中一个汉字占用 3个字节 而 HZK16 和 ASC16 字库是使用 GB2312
一个汉字 占用 2个字节
//在 Linux 下运行通过
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <iostream>
using namespace std;
/*
* the C/C++ File must use GB2312
* otherwise chinese words you read from hzk16 is incorrected
*/
class Font
{
protected:
enum {
TYPE_CHINESE,
TYPE_ENGLISH
}TYPE;
string m_word;
unsigned char buf[64];
FILE* fp;
virtual void GetWord(unsigned short word) = 0;
virtual void print(unsigned char* buf) = 0;
};
class FontChinese : public Font
{
void GetWord(unsigned short word)
{
if(fp != NULL)
{
int area = (word & 0xff) - 0xa0;
int bit = ((word >> 8) & 0xff) - 0xa0;
int offset = (94 * (area-1) + (bit-1)) * 32;
fseek(fp, offset, SEEK_SET);
fread(buf