The problem is that the original image is not exactly quadratic. When you do an AffineTransform rotation with at.rotate (-rad, width / 2, height / 2), this is the same as:
at.translate(width/2,height/2); at.rotate(rads); at.translate(-width/2,-height/2);
So, when it executes the last line, it leads to the beginning. And if the width is greater than y (or vice versa), then the origin of the transformation will be transferred to a shorter distance than the side of a larger length.
For example, if your width is 30 and your height is 60, then the start point will be set to (-15, -30), from which the original value was set. Thus, when you translate it, say, 90 degrees, the image will end with a “width” of 60 and a “height” of 30, but according to the starting point, the original bottom of the image will be drawn at (-30.0), so it overflows AffineTransform at -15 along the X axis. Then this part of the image will be cut out.
To fix this, you can use the following code:
double degreesToRotate = 90; double locationX =bufferedImage.getWidth() / 2; double locationY = bufferedImage.getHeight() / 2; double diff = Math.abs(bufferedImage.getWidth() - bufferedImage.getHeight());
Hope this helps.
Lucas borsatto
source share