【问题标题】:stbi_load cannot load imagestbi_load 无法加载图像
【发布时间】:2017-09-03 04:47:26
【问题描述】:

我正在尝试使用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 不,但就在刚才,我运行了stbi_failure_reason(),它返回了progressive jpeg。这是什么意思?

标签: c++


【解决方案1】:

所以答案很简单。如果您从本网站阅读:https://gist.github.com/roxlu/3077861

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

【讨论】:

    猜你喜欢
    • 2021-05-01
    • 1970-01-01
    • 2018-02-01
    • 2013-06-09
    • 2019-05-25
    • 2014-10-29
    • 2015-08-18
    • 2016-11-17
    • 2023-03-09
    相关资源
    最近更新 更多