您的位置:首页 > 运维架构 > Linux

嵌入式linux------SDL移植(am335x下显示bmp图片)

2015-07-28 15:51 597 查看
#include<stdio.h>
#include "/usr/local/ffmpeg_arm/include/SDL/SDL.h"
char *bmp_name[3] = {"000.bmp","111.bmp","222.bmp"};
int main()
{
int i=0;
//The images
SDL_Surface* hello = NULL;
SDL_Surface* screen = NULL;

//Start SDL
SDL_Init( SDL_INIT_EVERYTHING );
SDL_ShowCursor(0);
//Set up screen
screen = SDL_SetVideoMode( 1024, 768, 32, SDL_SWSURFACE );

while(30)
{
//Load image
hello = SDL_LoadBMP( bmp_name[i++%3]);

//Apply image to screen
SDL_BlitSurface( hello, NULL, screen, NULL );

//Update Screen
SDL_Flip( screen );

//Pause
SDL_Delay( 1000*2 );
}

//Free the loaded image
SDL_FreeSurface( hello );

//Quit SDL
SDL_Quit();

return 0;
}

编译命令:arm-linux-gcc bmp.c -o bmp -lpthread libSDL.a

参考:MFC下用sdl 显示bmp、rgb、yuv http://blog.csdn.net/mao0514/article/details/10007873
如果要显示jpg图片

SDL_image库的使用

SDL默认只支持bmp格式的图片显示,而大多数情况下,我们需要显示jpeg,png格式图片,这时候我们需要使用SDL扩展库。在开发前应先确认SDL_image库是否已编译安装成功。

首先需要先下载SDL_image,可以从SDL的官网获取最新版本。你也可以从其中的“Libraries”章节下载这个库,就在SDL的主页上。如果你不想为此麻烦,在本文件夹内已有SDL_image-1.2.10.tar.tar,只需按照《SDL编译移植文档》安装即可。

在程序中使用SDL_ttf库,必须使用如下头文件,注意SDL是大写

#include<SDL_image.h>

Linux应用程序链接时要也要链接这个库的-lSDL_image。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: