I am doing an assignment in which I have to manually mirror an image. I've been able to use image.pixelColor() to copy each color from a pixel and swap it with a pixel color in other position to mirror the image. But I've been unsuccessfully trying to do it by copying one row/column (block) of pixels at time using other methods (getPixels, setPixels, readPixels, writePixels, syncPixels).
Just to learn how to use the methods, I've been trying to do something like this, to copy a 50x50 block from the original to the new image:
Image original;
original.read("original.png");
Image new ("300x300", "white");
Quantum *block;
unsigned char *buffer;
original.modifyImage();
block = original.getPixels(0,0,50,50);//from image to pixel cache
original.writePixels(Magick::RGBQuantum, buffer); //from image pixel cache to buffer, region set by getPixels()
new.modifyImage();
new.setPixels(50,50,50,50);//alocate pixel cache region
new.readPixels(Magick::RGBQuantum, buffer); //from buffer to image pixel cache
new.syncPixels(); //from image pixel cache to image
original.display()
new.display();
It's not working as "new" is shown white with a 50x50 black region.
the issue is in
bufferand its usage inoriginal.writePixels(Magick::RGBQuantum, buffer);writePixelssaves data intobufferbut it's not initialized in your case.you should allocate some memory for the buffer: