我现在正在寻找几个图像处理库。昨天我发现了一些名为“ stb_image.h ”的库并尝试进行一些测试,但我无法读取 png 文件格式。当然,jpg 可以正常工作。只有png文件出现了问题。有没有人遇到过同样的问题?
我下载了链接下面的 stb_image.h 文件。
我做了一个如下所示的测试代码。
#include <iostream>
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
int main(int argc, const char * argv[]) {
int width, height, channel;
// try to load the jpg file format.
unsigned char *data = stbi_load("container.jpg", &width, &height, &channel, 0);
if (data) {
std::cout << "success load image : width=" << width << ", height=" << height << std::endl;
stbi_image_free(data);
}
else {
std::cout << "failed load image!" << std::endl;
}
// try to load the png file format.
data = stbi_load("aswesome.png", &width, &height, &channel, 0);
if (data) {
std::cout << "success load image : width=" << width << ", height=" << height << std::endl;
stbi_image_free(data);
}
else {
std::cout << "failed load image!" << std::endl;
}
return 0;
}