嵌入式 SDL把字符串转位图示例代码

int char_to_bmp_sdl(void) 

 TTF_Font *font; 
 SDL_Surface *text; 

 /* Initialize the TTF library */ 
 if ( TTF_Init() < 0 ) { 
  fprintf(stderr, "Couldn't initialize TTF: %s\n",SDL_GetError()); 
  SDL_Quit(); 
  return(2); 
 } 


 font = TTF_OpenFont("cu.ttf", 48); 
 if ( font == NULL ) {
  fprintf(stderr, "Couldn't open TTF: %s\n",SDL_GetError()); 
  return -1;
 } 

 //  TTF_SetFontStyle(font, 0); 
 //  TTF_SetFontOutline(font, 0); 
 //  TTF_SetFontKerning(font, 1); 
 //  TTF_SetFontHinting(font, 0); 

 //SDL_Color forecol=     { 0xFF, 0xFF, 0xFF, 0 }; 
 SDL_Color forecol=   { 0x00, 0x00, 0x00, 0 }; 
 char *string = "Mon Oct 28 10:33:23 CST 2013";
 text = TTF_RenderUTF8_Solid(font, string, forecol); 

 SDL_PixelFormat *fmt;
 fmt = (SDL_PixelFormat*)malloc(sizeof(SDL_PixelFormat));
 memset(fmt,0,sizeof(SDL_PixelFormat));
 fmt->BitsPerPixel = 16;
 fmt->BytesPerPixel = 2;
 fmt->Rmask = 0xff000000;//0x00FF0000
 fmt->Gmask = 0x0000ff00;//0x0000FF00
 fmt->Bmask = 0x00ff00ff;//0x000000FF
 fmt->Amask = 0;
 printf("%s %d\n ",__FUNCTION__,__LINE__);

 SDL_Surface *temp = SDL_ConvertSurface(text,fmt,0);

 SDL_SaveBMP(temp, "sdl_osd.bmp"); 

 SDL_FreeSurface(text); 
 SDL_FreeSurface(temp); 
 TTF_CloseFont(font); 
 TTF_Quit(); 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值