繁体   English   中英

SDL_image 无法初始化:SDL_image 错误。 加载 libpng16-16:dll 失败:找不到指定的模块

[英]SDL_image could not initialize! SDL_image Error: Failed loading libpng16-16.dll: The specified module could not be found

我花了最后一个小时试图找到解决此错误的方法。 我已经在 SO 和其他网站上搜索了所有答案,但到目前为止我发现的任何东西都没有用。 所以我在这里,迫切需要帮助。

首先是我正在使用的软件和库的版本:

  • SDL2-2.0.12
  • SDL2_image-2.0.5
  • VS 社区 2019

这是我对混乱区域的代码:

bool CApp::OnInit() {

if (SDL_Init(SDL_INIT_VIDEO) < 0) 
{
    printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError());
    return false;
}
else {

    std::cout << "SDL was initialized!!!" << std::endl;
}

// The window for the game.
Surf_Window = SDL_CreateWindow("SDL2 Window",
    SDL_WINDOWPOS_CENTERED,
    SDL_WINDOWPOS_CENTERED,
    screenWidth, screenHeight,
    0);

if (Surf_Window == NULL)
{
    return false;
}
else {

    std::cout << "Main Window was initialized!!!" << std::endl;
    //Initialize PNG loading
    int imgFlags = IMG_INIT_PNG;
    if (!(IMG_Init(imgFlags) & imgFlags))
    {
        printf("SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError());
        return false;
    }
    else
    {

        std::cout << "SDL_image was initialized!!!" << std::endl;
        //Get window surface
        Surf_Display = SDL_GetWindowSurface(Surf_Window);

        if (Surf_Display == NULL)
        {
            return false;
        }
    }
}

// Fill the window with White color.
SDL_FillRect(Surf_Display, NULL, SDL_MapRGB(Surf_Display->format, 0xFF, 0xFF, 0xFF));

// The image surface we load.
const char* image = "data/images/bgHomeScreen.bmp";
Surf_Test = CApp::OnLoad("data/images/bgHomeScreen.bmp");
//CSurface::OnLoad(Surf_Test, image);

if (Surf_Test == NULL) 
{
    printf("Unable to load image %s! SDL Error: %s\n", "data/images/bgHomeScreen.bmp", SDL_GetError());
    return false;
}

SDL_UpdateWindowSurface(Surf_Window);

SDL_Delay(2000);

return true;

}

这是我的项目设置的图像: 在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

我正在寻找修复此错误的方法,以便我可以继续学习 SDL2 的用途。

我解决了这个问题。 我将SDL2-2.0.12\lib\x86中的所有依赖项添加到我的项目 Release 和 Debug 目录中,程序按预期运行。 如果您计划使用 64 位,请记住复制 x64 文件夹而不是 x86。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM