Magick++: Why does image.crop() not respect the new image origin after rotation?
Posted: 2015-09-25T09:29:20-07:00
Hi,
I am trying to understand why image.crop() does not seem to respect the new origin which should be one of the effects of an image.rotate().
Platform: ImageMagick 6.9.2 Q16 x86 DLL on a Win10 x64 workstation. Code compiled with Visual Studio 2015.
In the sample below, I am creating a 141x141 blue square, then rotating the image through 45 degrees to arrive at "AfterRotation.JPG" which is 200x200. If I then crop() the image using "Geometry(100, 100, 0, 0)" the outcome is not what I expect. "AfterCrop.JPG" has the anticipated 100x100 dimensions, but instead of starting at (0, 0) of the rotated image its definition of the origin seems to correspond to the pre-rotation coordinate system. I do not understand that apparent discrepancy.
When the code is run, this is what "AfterRotate.JPG" looks like:
I expect "AfterCrop.JPG" to start at the origin (upper-left corner) of "AfterRotate.JPG". In other words, I expect "AfterCrop.JPG" to be the top-left quadrant of the "AfterRotate.JPG" image. Instead, "AfterCrop.JPG" looks like this:
Even though it is clearly operating on post-rotation buffer contents (the square edges are at a 45 degree angle), crop()'s definition of the origin does not correspond to the top-left corner of "AfterRotation.JPG".
What am I doing wrong?
Thanks in advance for all info and assistance.
I am trying to understand why image.crop() does not seem to respect the new origin which should be one of the effects of an image.rotate().
Platform: ImageMagick 6.9.2 Q16 x86 DLL on a Win10 x64 workstation. Code compiled with Visual Studio 2015.
In the sample below, I am creating a 141x141 blue square, then rotating the image through 45 degrees to arrive at "AfterRotation.JPG" which is 200x200. If I then crop() the image using "Geometry(100, 100, 0, 0)" the outcome is not what I expect. "AfterCrop.JPG" has the anticipated 100x100 dimensions, but instead of starting at (0, 0) of the rotated image its definition of the origin seems to correspond to the pre-rotation coordinate system. I do not understand that apparent discrepancy.
Code: Select all
#include <string>
#include <Magick++.h>
using namespace std;
using namespace Magick;
#pragma comment( lib, "CORE_RL_Magick++_" )
void main() {
InitializeMagick("");
Image image(Geometry("141x141"), Color("blue"));
image.rotate(45);
image.write("AfterRotate.jpg");
image.crop(Geometry(100, 100, 0, 0));
image.write("AfterCrop.jpg");
}
I expect "AfterCrop.JPG" to start at the origin (upper-left corner) of "AfterRotate.JPG". In other words, I expect "AfterCrop.JPG" to be the top-left quadrant of the "AfterRotate.JPG" image. Instead, "AfterCrop.JPG" looks like this:
Even though it is clearly operating on post-rotation buffer contents (the square edges are at a 45 degree angle), crop()'s definition of the origin does not correspond to the top-left corner of "AfterRotation.JPG".
What am I doing wrong?
Thanks in advance for all info and assistance.