我正在尝试加载8张图片。这些图像不加载,我不知道为什么。我使用Xcode将文件放到目录中。我认为我的代码可能有问题。
功能:
void loadImages() { for(int i = 0; i < 8; i++) pict[0] = NULL; pict[0] = IMG_Load("jpg/colorfull small jpg.jpg"); if(pict[0] == NULL) cout << "Unable to load image\n"; pict[1] = IMG_Load("jpg/colorfull big jpg.jpg"); if(pict[1] == NULL) cout << "Unable to load image\n"; pict[2] = IMG_Load("jpg/colorless small jpg.jpg"); if(pict[2] == NULL) cout << "Unable to load image\n"; pict[3] = IMG_Load("jpg/colorless big jpg.jpg"); if(pict[3] == NULL) cout << "Unable to load image\n"; pict[4] = IMG_Load("png/colorfull small png.png"); if(pict[4] == NULL) cout << "Unable to load image\n"; pict[5] = IMG_Load("png/colorfull big png.png"); if(pict[5] == NULL) cout << "Unable to load image\n"; pict[6] = IMG_Load("png/colorless small png.png"); if(pict[6] == NULL) cout << "Unable to load image\n"; pict[7] = IMG_Load("png/colorless big png.png"); if(pict[7] == NULL) cout << "Unable to load image\n"; }
编译器:
目录:
答案 0 :(得分:2)
确保您的流程的当前工作目录符合您的预期。
或使用绝对路径。