문제

I'm working on a type of image editor which includes snapping to other elements as a feature. The snapping works by using the image width and height.

However, after an AffineTransform.rotate() the image width and height are no longer the actual bounds of the rendered image and thus the snapping fails.

What's the best way of determining the width and height of the rectangular area that encompasses the rotated image?

도움이 되었습니까?

해결책

For int:

affineTransform.createTransformedShape(new Rectangle(width, height))
        .getBounds();

For double:

affineTransform.createTransformedShape(
        new Rectangle2D.Double(width, height)).getBounds2D();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top