[英]SDL_image could not initialize! SDL_image Error: Failed loading libpng16-16.dll: The specified module could not be found
I have spent the last hour trying to find a fix for this error.我花了最后一个小时试图找到解决此错误的方法。 I have searched all over SO and other sites for answers but nothing that I have found has worked so far.
我已经在 SO 和其他网站上搜索了所有答案,但到目前为止我发现的任何东西都没有用。 So here I am, in desperate need of help.
所以我在这里,迫切需要帮助。
First of here are the versions of software and libraries that I am using:首先是我正在使用的软件和库的版本:
Here is my code for the area that messes up:这是我对混乱区域的代码:
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;
} }
Here are images of my Project settings:这是我的项目设置的图像:
I am looking to fix this error so that I can continue to learn the uses of SDL2.我正在寻找修复此错误的方法,以便我可以继续学习 SDL2 的用途。
I figured out the problem.我解决了这个问题。 I added all of the dependencies from the
SDL2-2.0.12\lib\x86
to my projects Release and Debug directories and the program ran as expected.我将
SDL2-2.0.12\lib\x86
中的所有依赖项添加到我的项目 Release 和 Debug 目录中,程序按预期运行。 Just remember to copy the x64 folder instead of x86 if you plan on using 64 bit.如果您计划使用 64 位,请记住复制 x64 文件夹而不是 x86。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.