image.write() problems ...
Posted: 2014-04-09T21:33:24-07:00
Why would this not work:
But if I make a copy of the img object BEFORE I write it, then continue to process the copy, it works fine:
Does the .write() function clear the img object for some reason?
Code: Select all
Magick::Image img("test.png");
img.resize(Magick::Geometry(200, 200));
img.write("result.png");
for (col = img.columns() - 1; col >= 0; col--) { // reading right -> left
for (row = img.rows() - 1; row >= 0; row--) { // reading bottom -> top
Magick::ColorRGB rgb(img.pixelColor(col, row));
red = rgb.red() * 255;
green = rgb.green() * 255;
blue = rgb.blue() * 255;
// red, green, blue do NOT have correct values here
}
}
Code: Select all
Magick::Image img("test.png");
img.resize(Magick::Geometry(200, 200));
Magick::Image imgCopy = img; // make copy
img.write("result.png");
for (col = imgCopy.columns() - 1; col >= 0; col--) { // reading right -> left
for (row = imgCopy.rows() - 1; row >= 0; row--) { // reading bottom -> top
Magick::ColorRGB rgb(imgCopy.pixelColor(col, row));
red = rgb.red() * 255;
green = rgb.green() * 255;
blue = rgb.blue() * 255;
// red, green, blue are correct here
}
}