level 13
//源码
#include "SDL2/SDL.h"
#include<cstdio>
#include<vector>
#include "SDL_anigif.h"
int main(int argc,char**argv)
{
SDL_Event event;
bool g_bRunning = true;
int currentFrame = 0;
SDL_Rect destRect={0,0,0,0};
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Window*gWin = SDL_CreateWindow("gif test",SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,640,480,SDL_WINDOW_SHOWN);
SDL_Renderer*gRen = SDL_CreateRenderer(gWin,-1,SDL_RENDERER_ACCELERATED|SDL_RENDERER_PRESENTVSYNC);
//获取最大数量
int number = AG_LoadGIF("1.gif",NULL,0);
AG_Frame*frames = new AG_Frame[number];
AG_LoadGIF("1.gif",frames,number);
printf("the number of gif is:%d",number);
//获取大小
destRect.w = frames[0].surface->w;
destRect.h = frames[0].surface->h;
//由frames创建texture
std::vector<SDL_Texture*> textures;
for(int i=0;i<number;i++)
{
SDL_Texture*texture = SDL_CreateTextureFromSurface(gRen,frames[i].surface);
textures.push_back(texture);
}
while(g_bRunning)
{
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:
g_bRunning = false;
break;
}
}
SDL_SetRenderDrawColor(gRen,255,200,100,255);
SDL_RenderClear(gRen);
SDL_RenderCopy(gRen,textures.at(currentFrame++%number),NULL,&destRect);
SDL_RenderPresent(gRen);
SDL_Delay(frames->delay);
}
AG_FreeSurfaces(frames,number);
delete[] frames;
SDL_DestroyRenderer(gRen);
SDL_DestroyWindow(gWin);
return 0;
}
2016年05月13日 03点05分
5
思必达学院让你花一周时间,你就可以直接入职,完美上手,就是让你这么快, 思必达学院!
2016年06月23日 06点06分
level 13
刚才测试了一下,使用的时候,注意AG_Frame的x,y是偏移位置,而且每个surface的大小也是不同的,这个需要注意下
2016年05月13日 06点05分
11
level 1
gif说来也是种常用图像格式,SDL_image是处理图像项目,何不去修改SDL_image让支持gif呢。这样一来其它人要显示gif就像PNG一样简单了。
2016年05月13日 15点05分
13
gif相对来说并不好用,用gif虽然来自同一个文件,但纹理并不同。至于修改,感觉没必要
2016年05月14日 04点05分
@小牛_牛sky 刚看了一下,最新版的SDL_image 2.0.1已支持gif了。
2016年05月14日 06点05分
level 9
sdl的image扩展问题完全没必要,和你加载什么图片用相应的li
bp
ng libjpeg libgif开源库,直接输到到内存缓冲区,texture直接从缓冲区update就可以了
2016年05月14日 17点05分
16
给个例子。认例子不认人
![[太开心]](/static/emoticons/u592au5f00u5fc3.png)
而且我还特地问了SDL官方他们说暂时没有读取动态gif,然后给了我这个
2016年05月15日 00点05分
@小牛_牛sky 人家肯定认为没必要,懒得加入,做这个扩展大概半天就够了,再半天移植不同平台
2016年05月21日 16点05分
level 9
你可以直接拿libgif搞,SDL的颜色格式同一就可以,没有杂交不亲和
2016年05月14日 17点05分
17