如何將將字庫或圖片以數(shù)組的形式儲(chǔ)存在.c 文件中
我們新建一個(gè)xx.c文件,利用工具將我們所需要的漢字,字符,標(biāo)點(diǎn),生成16進(jìn)制的數(shù)組碼表,如下,
本文引用地址:http://www.ex-cimer.com/article/201611/322297.htm#definehzNum109
constunsignedcharhzIndex[218]={
0xc9,0xf9,0xd1,0xb8,0xb5,0xe7,0xd7,0xd3,
0xc9,0xe8,0xd6,0xc3,0xbf,0xec,0xbd,0xdd,
0xc7,0xeb,0xca,0xe4,0xc8,0xeb,0xb2,0xd9,
0xd7,0xf7,0xbf,0xda,0xc1,0xee,0xc8,0xb7,
0xb6,0xa8,0xc8,0xa1,0xcf,0xfb,0xca,0xfd,
0xc9,0xbe,0xb3,0xfd,0xb3,0xb7,0xb7,0xc0,
0xd4,0xda,0xbc,0xd2,0xb2,0xbc,0xcd,0xe2,
0xb3,0xf6,0xd1,0xa1,0xd4,0xf1,0xcd,0xcb,
0xd6,0xd0,0xb8,0xfc,0xb8,0xc4,0xd6,0xd8,
0xb7,0xb5,0xbb,0xd8,0xb1,0xa3,0xb4,0xe6,
0xca,0xc7,0xb7,0xf1,0xcf,0xfa,0xd6,0xf7,
0xd5,0xfd,0xb3,0xa3,0xb5,0xf4,0xb3,0xd8,
0xb3,0xe4,0xb7,0xc5,0xb1,0xa8,0xbe,0xaf,
0xce,0xfc,0xba,0xcf,0xb9,0xca,0xd5,0xcf,
0xcf,0xc2,0xd4,0xd8,0xcd,0xea,0xb3,0xc9,
0xce,0xde,0xb4,0xcb,0xc7,0xf8,0xb7,0xb6,
0xce,0xa7,0xc3,0xdc,0xc2,0xeb,0xa3,0xba,
0xa3,0xac,0xb4,0xed,0xce,0xf3,0xce,0xb4,
0xd0,0xe8,0xb9,0xa6,0xa3,0xa1,0xb2,0xbb,
}
constunsignedcharhzdot[3488]={
/*聲CC9F9*/
0x02,0x12,0xD2,0x52,0x52,0x52,0x52,0xDF,
0x52,0x52,0x52,0x52,0xD2,0x12,0x02,0x00,
0x40,0x30,0x0F,0x02,0x02,0x02,0x02,0x03,
0x02,0x02,0x02,0x02,0x07,0x00,0x00,0x00,
.
.
.
.
.}
此只是舉例而已,切記,此處生成的數(shù)組定義時(shí)要使用const來定義,不用static和extern,否則編譯時(shí)仍會(huì)報(bào)內(nèi)存不足情況,const就是修飾為常量,編譯器通常不為普通const常量分配存儲(chǔ)空間,而是將它們保存在符號(hào)表中,這使得它成為一個(gè)編譯期間的常量,沒有了存儲(chǔ)與讀內(nèi)存的操作,使得它的效率也很高,這就是const的神奇之處。
Xx.c文件中就是這些內(nèi)容,
Xx.H的內(nèi)容就是聲明和定義了,
#ifndef__xx_H__
#define__xx_H__
#definehzNum109
externconstunsignedcharchardot_8x16[];
externconstunsignedcharhzIndex[];
externconstunsignedcharhzdot[];
#endif
此文件中需要供外部使用,聲明前加上extern,在使用的開頭,#include”xx.h”就成功了!
評(píng)論