【问题标题】:SDL_Image IMG_Load() says the file format is not supportedSDL_Image IMG_Load() 表示不支持文件格式
【发布时间】:2015-02-04 20:07:28
【问题描述】:

我正在学习一个教程,我认为我做的一切都是正确的,但它继续说“不支持的图像格式”。

代码:

SDL_Texture *LoadTexture(string filePath, SDL_Renderer *renderTarget)
{
    SDL_Texture *texture = nullptr;
    SDL_Surface *surface = IMG_Load(filePath.c_str());

    if (surface == NULL)
    {
        cout << "Error: " << IMG_GetError() << endl;
    }
    else
    {
        texture = SDL_CreateTextureFromSurface(renderTarget, surface);

        if (texture == NULL)
        {
            cout << "Error: " << SDL_GetError() << endl;
        }
    }

    SDL_FreeSurface(surface);

    return texture;
}

表面在接受IMG_Load()的结果后保持NULL;

另外,我的包括:

#include <iostream>
#include <SDL2/SDL.h>
#include <SDL/SDL_image.h>

还有,我的初始化:

SDL_Init(SDL_INIT_VIDEO);

int image_flags = IMG_INIT_PNG;

if (IMG_Init(image_flags) != image_flags)
{
    cout << "Error: " << IMG_GetError() << endl;
}

另外,以防万一,我在 Ubuntu 中执行此操作,并且我最近从 Windows 切换,所以我可能无法正确处理库。

编辑:如果您要问,我正在尝试使用 PNG,所以我没有使用我尚未初始化的格式

【问题讨论】:

    标签: linux image ubuntu sdl sdl-2


    【解决方案1】:

    改变这个:

    #include <SDL/SDL_image.h> 
    

    #include <SDL2/SDL_image.h>
    

    您目前正在使用带有 SDL2 的 SDL_image(来自 SDL1)标头,我认为您的问题就在那里。如果没有安装 SDL2_image-dev,也许你需要安装它。

    【讨论】:

    • 天啊。愚蠢的错误。非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-03
    • 2019-05-25
    • 1970-01-01
    • 1970-01-01
    • 2016-10-03
    • 1970-01-01
    相关资源
    最近更新 更多