Reputation: 2614
I want change some colors of pixels and save changes, but not working. I have this loop. First I print on screen true value: like 255,173..., and second cout print on screen zeros. Until here is good.
for (int i = 0; i < image->width(); i++) {
for (int j = 0; j < image->height(); j++) {
QRgb pixelData = image->pixel(i,j);
int red = qRed(pixelData);
cout<<red<<endl;
image->setPixel(i, j, qRgb(0, 0, 0));
pixelData = image->pixel(i,j);
int red2 = qRed(pixelData);
cout<<red2<<endl;
}
}
After this loop I saved image. When I reopen or read this image. I got default values.
if (image->save(out.c_str())) {
std::cout << "save successful!" <<out<<std::endl;
}
Path is good. So I think setPixel not work for save function? How can I fix that?
Upvotes: 0
Views: 1476
Reputation: 2614
Problem is saving in JPG. Somehow this format change values and try making file smaller. I saving in PNG and my values stay like I want.
image.save("somefile.png", "PNG");
Upvotes: 0
Reputation: 2831
You have problems with save/load, not with setPixel. May be you need to specify a format while saving, for example:
image.save("somefile.jpg", "JPG");
Upvotes: 2