samedi 28 février 2015

lodepng, stb_image. Nothing works in my system for image loading in C++

I'm trying to load pngs or bmps into my programs. But none of the libraries I found around the web works. I have no idea why but I always get "incorrect PNG signature, it's no PNG or corrupted" for EVERY png when using lodepng. "unknown pixel format" for EVERY bmp when using SDL_loadBMP. "unknown image type" for every png when using stb_image.


I can't load anything. Maybe there is something wrong with my system ? I'm using OSX Yosemite. Here is the code. #include #include #define STB_IMAGE_IMPLEMENTATION



#include <lodepng.h>
#include <stb_image.h>

using namespace std;

int main (){


string name = "res/img_test.png";
const char * cstr = name.c_str();

//lodepng
unsigned char *buffer;
unsigned int w,h;
int result = lodepng_decode32_file(&buffer, &w, &h, cstr);
cout << lodepng_error_text(result) << endl;


//stb_image
int x, y, comp;

FILE *f = fopen(cstr, "rb");
unsigned char *res;
res = stbi_load_from_file(f,&x,&y,&comp,0);
fclose(f);

cout << stbi_failure_reason() << endl;



return 0;
}


I'm using latest cmake to build this with gcc. Any recommendatation is appreciated but consider this. I've tried many files (generated by me or grabbed from internet). Tested same files with other users of the these libraries. Their code worked and mine didn't.


Thanks.


Aucun commentaire:

Enregistrer un commentaire