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

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

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

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

这里是我的错误区域代码:

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。