freetype写BMP位图点阵
Freetype是将字库的字转换成一种色度的点阵,比如该例子中转换为256色的点阵。最终效果如下图
void *freetp_test(void *arg)
{
unsigned char fontbuffer[1025];
#if 1
printf("FT_Init_FreeType ");
berror = FT_Init_FreeType( & pFTLib );
if ( berror ) { printf("FT_Init_FreeType %d",berror); }
berror = FT_New_Face( pFTLib,
"/etc/arial.ttf",
0,
&pFTFace );
printf("FT_Init_FreeType %d *****\n",berror);
if ( ! berror)
{
printf("FT_Init_FreeType %d",berror);
FT_Set_Char_Size(pFTFace, 16 << 6 , 16 << 6 , 300 , 300 );
FT_Glyph glyph;
// load glyph 'C' 67 66 B
FT_Load_Glyph(pFTFace, FT_Get_Char_Index(pFTFace, chr ), FT_LOAD_DEFAULT);
berror = FT_Get_Glyph(pFTFace -> glyph, & glyph);
if ( ! berror)
{
// convert glyph to bitmap with 256 gray
FT_Glyph_To_Bitmap( & glyph, ft_render_mode_normal, 0 , 1 );
FT_BitmapGlyph bitmap_glyph = (FT_BitmapGlyph)glyph;
FT_Bitmap & bitmap = bitmap_glyph -> bitmap;
// while(1)
{
printf("freetp_test \n");
const char *file_bmp = "/home/user/linaro.bmp";
int fdb;
fdb= open(file_bmp, O_CREAT|O_RDWR,S_IRUSR|S_IWUSR);
if(fdb < 0)
{
printf("\n\n*************file creat fail***********\n\n");
exit(-1);
}
// fdb= write(fdb,bitmap.buffer,bitmap.width*bitmap.rows);
SetstringPlay(bitmap.buffer,bitmap.width*bitmap.rows,bx,by,bitmap.width,bitmap.rows);
if(fdb < 0)
{
printf("\n\n*************file write fail***********\n\n");
exit(-1);
}
close(fdb);
sleep(10);
}
for ( int i = 0 ; i < bitmap.rows; ++ i)
{
for ( int j = 0 ; j < bitmap.width; ++ j)
{
// if it has gray>0 we set show it as 1, o otherwise
printf( " %d " , bitmap.buffer[i * bitmap.width + j] ? 1 : 0 );
}
printf( " \n " );
}
// free glyph
FT_Done_Glyph(glyph);
glyph = NULL;
}
// free face
FT_Done_Face(pFTFace);
pFTFace = NULL;
}
// free FreeType Lib
FT_Done_FreeType(pFTLib);
pFTLib = NULL;
#endif
}
}
ASCII吗字符表
在shell里打印的一个数字 7
最后在屏幕上显示的
最新评论