码如下: 1. / 2. 函数名:PutChinese21 3. 描述 :显示单个汉字字符串 4. 输入 : pos: 0319-16 5. Ypos: 0239-16 6. str: 中文字符串首址 7. Color: 字符颜色 8. mode: 0--文字背景色为白色 9. 1--文字悬浮 10. 输出 :无 11. 举例 :PutChinese21200100quot好quot00 12. 注意 :如果输入大于 1 的汉字字符串,显示将会截断,只显示最前面一个汉字 13. / 14. void PutChinese21uint16_t Xposuint16_t Yposuint8_t struint16_t Co loru8 mode 15. 16. uint8_t ij 17. uint8_t buffer32 //32 字节用于保存字模数据 18. uint16_t tmp_char0 19. Set_direction0 20. GetGBKCode_from_sdbufferstr // 从 sd 卡中取出字模数据 21. 22. for i0ilt16i 23. 24. tmp_charbufferi2 25. tmp_chartmp_charltlt8 26. tmp_charbuffer2i1 10 / 28 未 来 之 芯,卓 我 M 3 27. for j0jlt16j 28. 29. if tmp_char gtgt 15-j amp 0x01 0x01 30. 31. LCD_Draw_ColorPointYposiXposjColor 32. 33. else 34. 35. if mode 0 36. LCD_Draw_ColorPointYposiXposj0xffff //背景 色显示白色 37. else if mode 1 38. 39. //不写入 40. 41. 42. 43. 44. 在 PutChinese21 这个函数中,首先从 sd 卡中读出我们需要显示在 lcd 上的指定汉字的字模数据,之后 2243 行的代码就根据字模数据来描写,描写这一部分在这里就不再说啦,和前面 VC 测试部分思路是一样的。
读者现在可能在想, 字库里面保存着大量的汉字字幕信息,我现在输入 GetGBKCode_from_sdbufferstr就能够拷贝出这个字符的字模数据,是怎样定位字模信息所在的位置的呢,换句话说,假如我现在要显示“吾”字,是怎样根据这个字来确定“吾”字符在字库中的保存位置的呢?其实这里面有一定的映射关系,那就是接下来要说的汉字“区码”和“位码”。
在汉字区位码表中,我们是如何定位我们指定汉字的编号的呢?接下来看看 vc6.0测试源码: 1. include ltstdio.hgt 2. void main 3. 4. unsigned char s e quotAquot c quot古quot 5. unsigned char high_bytelower_byte //内码高字节,内码低字节 6. printf quot字母s 的 ASCII 码quote 7. s e 8. 9. while s 0 //C 的字符串以 0 为结束符 10. 11. printf quot3dquot s 11 / 28 未 来 之 芯,卓 我 M 312. s 13. 14. printf quotn 汉字内码10 进制squotc 15.16. s c 17. while s 0 18. 19. printf quot3dquot s 20. s 21. 22.23. printf quotn 汉字内码16 进制squotc 24.25. s c 26. while s 0 27. 28. printf quot0Xquot s 29. s 30. 31.32.33. s c 34. high_byte s35.36. s 37. lower_byte s38.39. printfquotnn 汉字s对应的n 内码高字节:dn 内码低字 节:dnquotchigh_bytelower_byte40. printfquotnn 汉字s对应的n 区码为:d-160 dn 位码为:d- 160 dnquotchigh_bytehigh_byte-160lower_bytelower_byte-16041.42. printfquotnn 汉字s在区位码表中的位置为ddnquotchigh_byte- 160lower_byte-16043. printfquot汉字区位码表可参考网 站:http://cs.scu.edu.cn/wangbo/others/quweima.htmnquot44. printfquot通过在线查阅编号为dd 对应的汉字刚好就是snnquothigh_byte- 160lower_byte-160c 12 / 28 未 来 之 芯,卓 我 M 3 45. 46. 测试结果如下: 打开汉字区位码表在线查询网站:http://cs.scu.edu.cn/wangbo/others/quweima.htm 查询“古”汉字的区位码刚好如计算所得,为 。
上面的测试结果说明了每一个汉字的内码具体作用。
下面就来看看 PutChinese21函数中调用到的函数 GetGBKCode_from_sd 的源码: 1. / 2. 函数名:GetGBKCode_from_sd 3. 描述 :从 sd 卡上的字库文件中拷贝指定汉字的字模数据 4. 输入 : pBuffer---数据保存地址 5. c--汉字字符低字节码 6. 输出 : 0 成功 7. -1 失败 8. / 9. 10. int GetGBKCode_from_sdunsigned char pBufferunsigned char c 11. 12. unsigned char High8bitLow8bit 13. unsigned int pos 13 / 28 未 来 之 芯,卓 我 M 3 14. High8bitc 15. Low8bitc1 16. 17. pos High8bit-0xb094Low8bit-0xa1216 18. f_mount0 ampmyfs0 19. myres f_openampmyfsrc quot0:/HZLIB.binquot FA_OPEN_EXISTING FA_REA D 20. 21. if myres FR_OK 22. 23. f_lseek ampmyfsrc pos //制定读取位置 24. myres f_read ampmyfsrc pBuffer 32 ampmybr //1616 大小的汉 字其字模占用 162 个字节 25. f_closeampmyfsrc 26. 27. return 0 28. 29. 30. else 31. return -1 32. 33. pos High8bit-0xb094Low8bit-0xa1216 这条语句就是根据约定的映射关系由汉字内码求得该汉字字模在字库中的存放起始位置。
之后就到指定的位置去拷贝字模数据就可以了。
以上就是 SD 卡字库制作和现实的具体流程。
实现 SD 卡 BMP 图像的读取与保存 BMP 文件格式,又称为 Bitmap(位图)或是 DIBDevice-Independent Device,设备无关位图,是 Windows 系统中广泛使用的图像文件格式。
BMP 文件保存了一幅图象中所有的像素。
这种文件格式可以保存单色位图、16 色或 256 色索引模式像素图、24 位真彩色图象,每种模式种单一像素的大小分别为 1/8 字节,1/2 字节,1 字节和 3 字节。
目前最常见的是 256 色 BMP 和 24 位色 BMP。
这种文件格式还定义了像素保存的几种方法,包括不压缩、RLE 压缩等。
常见的 BMP 文件大多是不压缩的。
Windows 所使用的 BMP 文件,在开始处有一个文件头,大小为 54 字节。
保存了包括文件格式标识、颜色数、图象大小、压缩方式等信息,因为我们仅讨论 24 位色不压缩的 BMP,所以文件头中的信息基本不需要注意,只.
上一篇:
平板电脑MID主控芯片大全
下一篇:
秋天是疼痛的