I am experimenting with reading the width and height of a PNG file. This is my code:
struct TImageSize { int width; int height; }; bool getPngSize(const char *fileName, TImageSize &is) { std::ifstream file(fileName, std::ios_base::binary | std::ios_base::in); if (!file.is_open() || !file) { file.close(); return false; }
If I try to read, for example, this image from Wikipedia , I get these incorrect values:
252097920 (should be 800)
139985408 (should be 600)
Note that the function does not return false, so the contents of the variable width and height must come from the file.
source share