stbi_load cannot load image

c++
12,104

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)

Share:
12,104
Author by

Hung Truong

Updated on June 14, 2022

Comments

  • Hung Truong 7 months

    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 ?