3520a SDL_tff库做bmp 也就是osd
生活随笔
收集整理的这篇文章主要介绍了
3520a SDL_tff库做bmp 也就是osd
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
之前用点陈字库做过3515,3520a的字库,现在为新需求,要用矢量字库做osd。决定用SDL_tff库做。
配置freetype:
xy@xy-pc:~/aaa/freetype-2.4.10$ CC=arm-hisiv200-linux-gcc ./configure --prefix=/home/xy/aaa/bin --host=arm-linux编译安装:make ,make install。
配置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
编译安装。
配置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
编译安装.
/** main.c** Created on: 2013-1-22* Author: xy*/ #include <stdlib.h> #include <string.h> #include "SDL/SDL.h" #include "SDL/SDL_ttf.h"int main(int argc,char **argv) {TTF_Font *font;SDL_Surface *text, *temp;/* 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 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_LoadBMPSDL_SaveBMP(text, "1.bmp");SDL_FreeSurface(text);TTF_CloseFont(font);TTF_Quit();}
就可以保存成1.bmp了。输入了汉字。代码保存的文本格式应该utf-8.
对于海思3520a用的是rgb1555格式,所以应该转成那种格式:
/* Convert to 16 bits per pixel */SDL_Surface *temp = SDL_CreateRGBSurface(SDL_SWSURFACE,text->w, text->h, 16,\0x00FF0000, 0x0000FF00, 0x000000FF,/*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);
添加以上代码,基本就可以达到了。
因为自己的不细心,调试了大半天。真是不应该啊。其实早知道这样做,但是思维上总是背道而驰。
以后编程应该更细心,至少节省时间啊。。。。
与50位技术专家面对面20年技术见证,附赠技术全景图总结
以上是生活随笔为你收集整理的3520a SDL_tff库做bmp 也就是osd的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 浅析gcc内嵌汇编
- 下一篇: vs2005添加live555工程