2017-09-03 158 views
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。有人可以告诉我这个代码有什么问题,导致imgDataNULL(图片是*.jpg文件,如果有人想知道)。任何帮助将不胜感激!

编辑:我跑stbi_failure_reason(),它返回progressive jpeg。这是什么意思 ?

+0

您是否尝试过通过它在调试器步进看哪里/为什么失败? – tkausl

+0

@tkausl不,但是就在刚才,我跑了'stbi_failure_reason()',并且它返回了'progressive jpeg'。这是什么意思 ? –

回答

1

事实证明,答案非常简单。如果您从本网站阅读:https://gist.github.com/roxlu/3077861

你会看到,stb_image不支持progressive JPEG图像格式(我甚至不知道存在)