image.write() problems ...

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
kirash4
Posts: 34
Joined: 2010-04-12T15:30:59-07:00
Authentication code: 8675308

image.write() problems ...

Post by kirash4 »

Why would this not work:

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
  }
}
But if I make a copy of the img object BEFORE I write it, then continue to process the copy, it works fine:

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
  }
}
Does the .write() function clear the img object for some reason?
Post Reply