I am trying to save a 5x5 pixel image, read from glReadPixels into a file using SOIL.
I read the pixels:
int x = 400; int y = 300; std::vector< unsigned char* > rgbdata(4*5*5); glReadPixels(x, y, 5, 5,GL_RGBA,GL_UNSIGNED_BYTE, &rgbdata[0]);
Then I will try to save the read data with the image save function SOIL
int save_result = SOIL_save_image ( "image_patch.bmp", SOIL_SAVE_TYPE_BMP, 5, 5, 4, rgbdata[0] );
But when I try to save the image, I get an unhandled exception.
Solution (Christian Rau)
int x = 400; int y = 300; std::vector< unsigned char > rgbdata(4*5*5); glReadPixels(x-(5/2), y-(5/2), 5, 5,GL_RGBA,GL_UNSIGNED_BYTE, &rgbdata[0]); int save_result = SOIL_save_image ( "image_patch.bmp", SOIL_SAVE_TYPE_BMP, 5, 5, 4, rgbdata.data() );
source share