嵌入式 hi3518cSDL_tff库做bmp实现osd

配置freetype:

xy@xy-pc:~/aaa/freetype-2.4.10$CC=arm-hisiv200-linux-gcc ./configure --prefix=/home/xy/aaa/bin--host=arm-linux

编译安装:make ,makeinstall。

配置SDL:

xy@xy-pc:~/aaa/SDL-1.2.15$CC=arm-hisiv200-linux-gcc CXX=arm-hisiv200-linux-cpp ./configure--prefix=/home/xy/aaa/bin --host=arm-linux --disable-alsa--disable-pulseaudio

编译安装。

make

make install


配置SDL_tff:

xy@xy-pc:~/aaa/SDL_ttf-2.0.11$CC=arm-hisiv200-linux-gcc./configure --with-freetype-prefix=/home/xy/aaa/bin--host=arm-linux

编译安装.


  1. #include
  2. #include
  3. #include "SDL/SDL.h"
  4. #include"SDL/SDL_ttf.h"
  5. int main(int argc,char**argv)
  6. {
  7. TTF_Font *font;
  8. SDL_Surface *text, *temp;
  9. if ( TTF_Init() < 0 ){
  10. fprintf(stderr, "Couldn't initialize TTF:%s\n",SDL_GetError());
  11. SDL_Quit();
  12. return(2);
  13. }
  14. font = TTF_OpenFont("cu.ttf", 48);
  15. if ( font == NULL ){
  16. fprintf(stderr, "Couldn't load %d pt font from %s:%s\n",
  17. "ptsize", 18,SDL_GetError());
  18. }
  19. //TTF_SetFontStyle(font, 0);
  20. // TTF_SetFontOutline(font, 0);
  21. //TTF_SetFontKerning(font, 1);
  22. // TTF_SetFontHinting(font, 0);
  23. //SDL_Color forecol= { 0xFF, 0xFF, 0xFF, 0};
  24. SDL_Color forecol= { 0x00, 0x00, 0x00, 0 };
  25. char*string="你好啊";
  26. text = TTF_RenderUTF8_Solid(font, string,forecol);
  27. //SDL_LoadBMP
  28. SDL_SaveBMP(text, "1.bmp");
  29. SDL_FreeSurface(text);
  30. TTF_CloseFont(font);
  31. TTF_Quit();
  32. }
#include 
#include 
#include "SDL/SDL.h"
#include "SDL/SDL_ttf.h"


int main(int argc,char **argv)
{
        TTF_Font *font;
        SDL_Surface *text, *temp;

         
         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 load %d pt font from %s: %s\n",
                                        "ptsize", 18, SDL_GetError());
        }

//      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="你好啊";
        text = TTF_RenderUTF8_Solid(font, string, forecol);

        //SDL_LoadBMP

        SDL_SaveBMP(text, "1.bmp");




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

}

就可以保存成1.bmp了。输入了汉字。代码保存的文本格式应该utf-8.



对于海思3520a用的是rgb1555格式,所以应该转成那种格式:

  1. SDL_Surface *temp =SDL_CreateRGBSurface(SDL_SWSURFACE,
  2. text->w, text->h, 16,\
  3. 0x00FF0000, 0x0000FF00, 0x000000FF,
  4. 0);
  5. SDL_Rect bounds;
  6. if (temp !=NULL)
  7. {
  8. bounds.x = 0;
  9. bounds.y = 0;
  10. bounds.w = text->w;
  11. bounds.h = text->h;
  12. if (SDL_LowerBlit(text,&bounds, temp, &bounds) < 0) {
  13. SDL_FreeSurface(text);
  14. SDL_SetError("Couldn't convert image to 16bpp");
  15. text = NULL;
  16. }
  17. }
  18. stBitmap.u32Width = temp->w;
  19. stBitmap.u32Height = temp->h;
  20. stBitmap.pData= temp->pixels;
  21. stBitmap.enPixelFormat= PIXEL_FORMAT_RGB_1555;
  22. SDL_FreeSurface(text);
  23. SDL_FreeSurface(temp);
       
        SDL_Surface *temp = SDL_CreateRGBSurface(SDL_SWSURFACE,
                        text->w, text->h, 16,\
                                                0x00FF0000, 0x0000FF00, 0x000000FF,
                                                0);
        SDL_Rect bounds;
        if (temp != NULL)
        {
                bounds.x = 0;
                bounds.y = 0;
                bounds.w = text->w;
                bounds.h = text->h;
                if (SDL_LowerBlit(text, &bounds, temp, &bounds) < 0) {
                        SDL_FreeSurface(text);
                        SDL_SetError("Couldn't convert image to 16 bpp");
                        text = NULL;
                }
        }
        stBitmap.u32Width = temp->w;
        stBitmap.u32Height = temp->h;
        stBitmap.pData= temp->pixels;
        stBitmap.enPixelFormat= PIXEL_FORMAT_RGB_1555 ;
        SDL_FreeSurface(text);
        SDL_FreeSurface(temp);

添加以上代码,基本就可以达到了。

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值