Search code examples
c++imagergbpixelcimg

CImg saving images changes values?


So I am using the CImg library to have some fun with images... The issue is that when I open a file to change its RGB values and save, the modified image does not retain the changed values OR the original value.

CImg<unsigned char> image_out( img.c_str() );
image_out(0,0,0) = 253; //reset new rgb values
image_out(0,0,1) = 248;
image_out(0,0,2) = 251;
image_out.save( "out.jpeg" );

Then when I open the image again, I get this as the new RGB values...

R: 249  G: 249  B: 249

I don't really understand why the values aren't being saved to the ones I set...

edit: Sorry also mentioning I KNOW the initial value of the pixel (respect to RGB) is 255, 255, 255.


Solution

  • Don't use jpeg, this is a destructive image format that doesn't preserve the values, due to the Dct compression. Use .png or. Bmp instead.