Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stbi_load cannot load image

Tags:

I'm trying to load a texture using stbi_load(). Here's my code:

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);

And when I run the program, it says Cannot load texture. I don't know what's wrong. I am sure that the filename is a valid path, because when I write:

std::ifstream infile(fileName);

if (infile.good())
{
    cout << "Good" << endl;
}
else
{
    cout << "Not good" << endl;
}

It produces Good. Can someone tell me what is wrong with this code that causes imgData to be NULL (The image is a *.jpg file, if anybody was wondering). Any help would be highly appreciated!

Edit : I ran stbi_failure_reason() and it returned progressive jpeg. What does this mean ?

like image 960
Hung Truong Avatar asked Sep 03 '17 04:09

Hung Truong


1 Answers

So it turns out the answer was really easy. If you read from this website : https://gist.github.com/roxlu/3077861

You'll see that stb_image doesn't support progressive JPEG image format (which I didn't even knew existed)

like image 140
Hung Truong Avatar answered Oct 12 '22 09:10

Hung Truong