STBI_LOAD无法加载图像
stbi_load cannot load image
我正在尝试使用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
。这是什么意思?
,因此答案确实很容易。如果您从此网站阅读:https://gist.github.com/roxlu/3077861
您会看到stb_image
不支持progressive JPEG
图像格式(我什至不知道存在)
如stbi_image源代码(https://gist.github.com/1271/970F5FE47CF721C6CE5D8B75D28B75D2840C46#FILE-STB_IMAGE-C>)
有这样的限制:
- no jpeg progressive support
- non-HDR formats support 8-bit samples only (jpeg, png)
- no delayed line count (jpeg) -- IJG doesn't support either
- no 1-bit BMP
- GIF always returns *comp=4
至于渐进式jpeg:
与标准JPEG相比,主要区别在于图像的加载方式。
- 标准jpeg格式一次从上到下加载一行一行,每行都是像素完美的。
- 对于渐进的JPEG而言,图像全部出现在整体上,但它会模糊和像素化。逐渐地,您会看到一个清晰且满载的图像。
如何检查JPEG文件是否渐进:
您可以遵循此答案的指示:https://superuser.com/a/1617350/1319167
相关文章:
- 使用 SDL2 和SDL_image C++加载图像
- 在 gtkmm 中异步加载图像
- QImage:加载图像时自动检测格式
- 使用 OpenGL 加载图像时0x69ABF340 STBI_Image引发异常
- 无法在 macOS 上的 SDL 游戏中加载图像
- HDFql 保存和加载图像
- 我无法使用Win32从文件夹中加载图像
- QT 无法从缓冲区加载图像
- SDL_2加载图像不起作用
- QWebview:关闭在QWebview qt加载图像
- QLabel 从文件加载图像
- 加载图像函数在qt快速源代码
- 从CUDA中的指针加载图像并导出dll
- 加载图像约500次后,此错误显示在Visual Studio Qimage:不记忆,返回空图像
- OPENCV_使用OpenCV2的加载图像中的异常
- STBI_LOAD无法加载图像
- C++ SFML 2.0 从文件加载图像
- 如何使用咖啡加载图像
- 如何使用OpenCV加载图像(原始字节)
- 需要从数据库 c++ 加载图像