SDL编译安装图片显示-sdwebimage加载超大图片

SDL编译安装图片显示

1.SDL简介

 SDL(Simple DirectMediaLayer)是一套开放源代码的跨平台多媒体开发库,使用C语言写成。SDL提供了数种控制图像、声音、输出入的函数,让开发者只要用相同或是相似的代码就可以开发出跨多个平台(Linux、Windows、MacOS X等)的应用软件。现SDL多用于开发游戏、模拟器、媒体播放器等多媒体应用领域。

  在编译SDL库前,先安装以下工具:

复制sudo apt-get install autoconf sudo apt-get install automake sudo apt-get install libtool sudo apt-get install make sudo apt-get install xorg-dev

2. SDL库编译与安装

 下载地址:SDL2.0

 (1)将下载的SDL2-2.0.14.tar.gz压缩包拷贝至虚拟机解压。 复制[wbyq@wbyq src_pack]$ tar xvf /mnt/hgfs/ubuntu/software_pack/SDL2-2.0.14.tar.gz

 (2)配置编译安装路径

复制[wbyq@wbyq SDL2-2.0.14]$ ./autogen.sh [wbyq@wbyq SDL2-2.0.14]$ ./configure –prefix=$PWD/_install [wbyq@wbyq SDL2-2.0.14]$ make && make install

 (3)编译成功生成文文件

复制[wbyq@wbyq _install]$ ls bin include lib share

1.3 SDL2_image库编译与安装

  bmp_surface加载jpg格式图片和png格式图片需要相对应库支持

复制[wbyq@wbyq src_pack]$ sudo apt-get install libjpeg-dev #安装jpg库 [wbyq@wbyq src_pack]$ sudo apt-get install libpng-dev #安装png库

 下载地址:

SDL_IMAGE

 (1)将 SDL2_image-2.0.5.tar.gz压缩包拷贝至虚拟机解压。 复制[wbyq@wbyq src_pack]$ tar xvf /mnt/hgfs/ubuntu/software_pack/SDL2_image-2.0.5.tar.gz

 (2)配置编译安装路径

复制[wbyq@wbyq SDL2_image-2.0.5]$ ./autogen.sh [wbyq@wbyq SDL2_image-2.0.5]$ ./configure –prefix=$PWD/_install [wbyq@wbyq SDL2_image-2.0.5]$ make && make install

 (3)编译成功生成文文件

复制[wbyq@wbyq _install]$ tree . ├── include │ └── SDL2 │ └── SDL_image.h └── lib ├── libSDL2_image-2.0.so.0 -> libSDL2_image-2.0.so.0.2.3 ├── libSDL2_image-2.0.so.0.2.3 ├── libSDL2_image.a ├── libSDL2_image.la ├── libSDL2_image.so -> libSDL2_image-2.0.so.0.2.3 └── pkgconfig └── SDL2_image.pc 4 directories, 7 files

1.4 示例1:SDL显示图片和获取输入出设备数据

 1.4.1 示例代码 复制#include #include #include #include typedef enum { false, true } bool; int main(int argc,char *argv[]) { if(SDL_Init(SDL_INIT_VIDEO))/*初始化SDL*/ { printf(“初始化失败ERR=%srn”,SDL_GetError()); return 0; } /*创建SDL窗口*/ SDL_Window *window=SDL_CreateWindow(“SDL Test”, SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,800,480,SDL_WINDOW_SHOWN); SDL_Rect rect; rect.x=0; rect.y=0; SDL_Surface *surface=SDL_GetWindowSurface(window);/*获取窗口*/ SDL_Surface *pngsurface=IMG_Load(“bg6.png”); SDL_Surface *bmp_surface=IMG_Load(“1.bmp”); SDL_BlitSurface(bmp_surface,NULL,surface,NULL); SDL_UpdateWindowSurface(window);/*刷新窗口*/ bool quit= true; SDL_Event event; while(quit) { while(SDL_PollEvent(&event))/*监测事件*/ { if(event.type==SDL_QUIT)//关闭窗口 { printf(“hello,worldn”); quit=false; printf(“quit=%dn”,quit); } else if(event.type==SDL_MOUSEBUTTONDOWN)/*鼠标点击事件*/ { if(event.button.button==SDL_BUTTON_LEFT)/*左键*/ { printf(“left clickedn”); SDL_BlitSurface(bmp_surface,NULL,surface,NULL); } if(event.button.button==SDL_BUTTON_RIGHT)/*右键*/ { printf(“right clickedn”); SDL_BlitSurface(pngsurface,NULL,surface,NULL); } } else if(event.type==SDL_KEYDOWN)//键盘事件 { printf(“key=%dn”,event.key.keysym.sym); if(event.key.keysym.sym==SDLK_UP) { rect.y-=10; printf(“upn”); } else if(event.key.keysym.sym==SDLK_DOWN) { rect.y+=10; printf(“downn”); } else if(event.key.keysym.sym==SDLK_LEFT) { rect.x-=10; printf(“leftn”); } else if(event.key.keysym.sym==SDLK_RIGHT) { rect.x+=10; printf(“rightn”); } SDL_BlitSurface(bmp_surface,NULL,surface,NULL); SDL_BlitSurface(pngsurface,NULL,surface,&rect); } SDL_UpdateWindowSurface(window);/*刷新窗口*/ } } SDL_FreeSurface(surface); SDL_DestroyWindow(window);/*销毁窗口*/ SDL_Quit();/*关闭SDL*/ return 0; } 1.4.2 Makefile文件 复制CFLAGS =-I/home/wbyq/src_pack/SDL2-2.0.14/_install/include -I/home/wbyq/src_pack/SDL2-2.0.14/_install/include/SDL2 -L/home/wbyq/src_pack/SDL2-2.0.14/_install/lib CFLAGS +=-L/home/wbyq/src_pack/SDL2_image-2.0.5/_install/lib -I/home/wbyq/src_pack/SDL2_image-2.0.5/_install/include -I/home/wbyq/src_pack/SDL2_image-2.0.5/_install/include/SDL2 CFLAGS+=-lSDL2 -lpthread -lm -ldl -lSDL2_image app: gcc 01sdl_test.c $(CFLAGS) 1.4.3 运行效果 SDL编译安装图片显示-sdwebimage加载超大图片
审核编辑:汤梓红

免责声明:文章内容来自互联网,本站不对其真实性负责,也不承担任何法律责任,如有侵权等情况,请与本站联系删除。
转载请注明出处:SDL编译安装图片显示-sdwebimage加载超大图片 https://www.yhzz.com.cn/a/7154.html

上一篇 2023-04-17 17:19:20
下一篇 2023-04-17 17:25:47

相关推荐

联系云恒

在线留言: 我要留言
客服热线:400-600-0310
工作时间:周一至周六,08:30-17:30,节假日休息。