0
我试图使用stbi_load()
加载纹理。这里是我的代码:stbi_load无法加载图像
int width, height, numComponents;
unsigned char* imgData = stbi_load(fileName.c_str(), &width, &height, &numComponents, 4);
if (imgData == NULL)
cout << "Cannot load texture" << endl;
//some code
//free
stbi_image_free(imgData);
而当我运行该程序时,它说Cannot load texture
。我不知道什么是错的。我相信,文件名是一个有效的路径,因为当我写:
std::ifstream infile(fileName);
if (infile.good())
{
cout << "Good" << endl;
}
else
{
cout << "Not good" << endl;
}
它产生Good
。有人可以告诉我这个代码有什么问题,导致imgData
为NULL
(图片是*.jpg
文件,如果有人想知道)。任何帮助将不胜感激!
编辑:我跑stbi_failure_reason()
,它返回progressive jpeg
。这是什么意思 ?
您是否尝试过通过它在调试器步进看哪里/为什么失败? – tkausl
@tkausl不,但是就在刚才,我跑了'stbi_failure_reason()',并且它返回了'progressive jpeg'。这是什么意思 ? –