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工程