[Solved] C++ PNG Decoder Error


The error is self-explanatory. You are not passing in the correct parameters that decode() is expecting.

Look at the actual declaration of the decode() overload that you are trying to call (there are 3 overloads available):

unsigned decode(std::vector<unsigned char>& out, unsigned& w, unsigned& h,
                const std::string& filename,
                LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8);

In particular, notice that the 2nd and 3rd parameters are passed by non-const references. Your code is declaring int variables that are type-casted to unsigned when passed to those parameters. The compiler would have to create temporary unsigned variables to hold the values, but temporaries cannot bind to non-const references.

So, your code DOES NOT match the declaration of that decode() overload (or any of the overloads, for that matter). Hence, the error message that no overloads of decode() can be found that accept the parameters you are passing in is correct. And, if you actually read the error message more carefully, it shows you the argument types that the compiler detected, which you can clearly see do not match the declaration of the decode() overload you are trying to call.

You need to change your width and height variables from int to unsigned, and get rid of the type-casts:

const char* path = "image.png";
unsigned height = 256, width = 256;
vector<unsigned char> image;
unsigned error = lodepng::decode (image, width, height, path);

solved C++ PNG Decoder Error