c++magick++

How can I set pixel value on Magick++ 7?


I'm able to get the values using MagickCore::Quantum, but I'm still not able to set RGB values for a pixel.


Solution

  • I'm assuming you are getting the pixels into a cache with Magick::Image.getPixels.

    After editing the Quantum values, just call Magick::Image.syncPixels to copy the values back.

    Magick::Image img("rose:");
    // Create cache of pixel data
    Magick::Quantum * pixels = img.getPixels(5, 5, 1, 1);
    // Set values
    Magick::Color green("GREEN");
    pixels[0] = green.quantumRed();
    pixels[1] = green.quantumGreen();
    pixels[2] = green.quantumBlue();
    // Copy cache back.
    img.syncPixels();
    img.write("output.png");