#include <iostream>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
int main()
{
sf::Image input;
sf::Color currentPix;
// input.bmp is a 100*100 red square
input.loadFromFile("input.bmp");
currentPix = input.getPixel(0,0); // top-left corner red pixel
std::cout << std::endl << " R : " << (int)currentPix.r << ", G : " << (int)currentPix.g << ", B : " << (int)currentPix.b;
std::cout << ", A : " << (int)currentPix.a;
// Some changes
currentPix.r++;
currentPix.g++;
currentPix.b++;
currentPix.a--; // I can't use ++ since 255 is the maximum
input.setPixel(0,0,currentPix);
std::cout << std::endl << " new R : " << (int)currentPix.r << ", new G : " << (int)currentPix.g << ", new B : " << (int)currentPix.b;
std::cout << ", new A : " << (int)currentPix.a << std::endl;
input.saveToFile("output.bmp");
}
It shows : R : 237, G : 28, B : 36, A : 255
newR : 238, G : 29, B : 37, A : 254
However, when I open the image with gimp and check the color of the pixel I changed, or if I load the file and check the pixel with getPixel(),
the pixel in 0,0 will be {239,28,38,255} instead of the expected {238,29,37,254};.