SDL加载我的图像搞砸了
SDL loading my image messed up
我要加载一张从flash CS3导出的图片它看起来很可爱,但加载时却很奇怪加载时呈现蓝色这是这两个文件的代码:
//main.cpp
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include "test.hpp"
int main(int argc, char *argv[])
{
SDL_Init(SDL_INIT_VIDEO);
// Activamos modo de video
screen = SDL_SetVideoMode(640,480,32,SDL_SWSURFACE | SDL_DOUBLEBUF);
image = IMG_Load("face.bmp");
dest.x = 200;
dest.y = 200;
//Main Loop
while(Abierto)
{
//We Draw
Draw();
//Events
while( SDL_PollEvent(&event))
{
if(event.type == SDL_QUIT)
Abierto = false;
}
}
// We free the image
SDL_FreeSurface(image);
SDL_Quit();
return 0;
}
另一个是;
//test.hpp
DL_Surface *image = NULL, *screen = NULL;
SDL_Rect dest;
SDL_Event event;
bool Abierto = true;
float PlaneX = 300, PlaneY = 200;
float velX = 0.1, velY = 0.1;
void Draw()
{
Uint32 color;
// Black Background is created
color = SDL_MapRGB (screen -> format, 0, 0, 0);
SDL_FillRect (screen, NULL, color);
SDL_DisplayFormatAlpha(image);
SDL_BlitSurface(image, NULL, screen, &dest);
// Flip the working image buffer with the screen buffer
SDL_Flip (screen);
}
我需要帮助,请我没有经验的SDL的东西哦,如果你想仔细看看我上传的项目在这里。
哦,不好意思,我必须根据flash导出选项添加32像素的alpha图像
根据docs, SDL_DisplayFormatAlpha
返回一个新图像并保持原始图像的完整。
那么,在第一部分中,当你加载图像时:
SDL_Surface *origImage = IMG_Load("face.bmp");
image = SDL_DisplayFormatAlpha(origImage);
SDL_FreeSurface(origImage)
由于不需要每一帧调用SDL_DisplayFormatAlpha
。
然后在第二部分,只blit image
,不调用SDL_DisplayFormatAlpha
。
我刚看了你的照片,它看起来像一个奇怪的 bmp。我以前见过:BMP格式是如此的混乱,如果你不保持基本的机会是不同的程序将解释不同的数据。
在你的例子中:
-
display face.bmp
显示正确 -
gthumb face.bmp
无显示 -
eog face.bmp
显示"伪造头数据"。
我强烈建议所有游戏卡通类图片使用PNG文件,所有照片类图片使用JPG文件。
所以运行
$ convert face.bmp face.png
并使用PNG文件。这样效果会更好,文件的大小是原来的20%
相关文章:
- 无法将图像加载到纹理矢量 (SFML)
- 如何将硬编码图像加载到 OpenGL 纹理中
- C++ SDL2 图像加载格式与.bmp不同
- 土壤图像加载库参数
- 示例文件中的CImg图像加载错误
- OpenGL图像加载64位深度
- SFML图像加载在发布版本上失败 - 文件名损坏
- 如何将图像加载到painter.drawimage函数
- 将图像加载到Mat-vvector<向量<垫子>>
- OpenCV图像加载程序退出
- 从字节数组将图像加载到图形视图中
- 将图像加载到现有Mat中
- 处理文件和图像加载异常的最佳方法是什么?
- 将PNG或JPG图像加载到CMFCToolBarImages中
- stb图像加载库返回白色纹理
- 创建垫子后,从字节向量将图像加载到垫子上
- 图像加载功能不工作
- 将UTF-16图像加载到内存中
- 我怎么能得到像素的颜色在我的图像(加载灰色)
- 正在将位图图像加载到按钮