I want to crop part of the image and then write the result to another image file. My code looks like this
ImageInfo imageInfo = new ImageInfo("file path");
MagickImage image = new MagickImage(imageInfo );
Rectangle cropInfo = new Rectangle();
cropInfo.x = 20;
cropInfo.y = 20;
cropInfo.width = 300;
cropInfo.height = 300;
MagickImage result = image.cropImage(cropInfo);
result.setFileName("path to result file");
boolean s = result.writeImage(imageInfo);
The above code just works but why writeImage using the old ImageInfo? and the MagickImage.setFileName don't make sense to me. I think we should create a new ImageInfo object and then write to that ImageInfo. The following code make more sense but don't work as expected.
MagickImage result = image.cropImage(cropInfo);
ImageInfo resulInfo = new ImageInfo("path to new file");
boolean s = result.writeImage(imageInfo);
Does anyone experience with this ?
It was inconvenient for me to keep the original ImageInfo around, so I tried this and it also worked:
As to why the parameter is needed at all, the mystery remains. Null will not work.