question: public static BufferedImage rotate ( final BufferedImage src , final int rotation ) { BufferedImage dst ; if ( src == null ) { return null ; } if ( rotation == 0 ) { return src ; } final double angle = rotation * Math . PI / 180 ; final int w = src . getWidth ( ) ; final int h = src . getHeight ( ) ; final int newW = ( int ) ( Math . round ( h * Math . abs ( Math . sin ( angle ) ) + w * Math . abs ( Math . cos ( angle ) ) ) ) ; final int newH = ( int ) ( Math . round ( h * Math . abs ( Math . cos ( angle ) ) + w * Math . abs ( Math . sin ( angle ) ) ) ) ; final AffineTransform at = AffineTransform . getTranslateInstance ( ( newW - w ) / 2 , ( newH - h ) / 2 ) ; at . rotate ( angle , w / 2 , h / 2 ) ; dst = new BufferedImage ( newW , newH , BufferedImage . TYPE_INT_ARGB ) ; final Graphics2D g2 = dst . createGraphics ( ) ; g2 . drawRenderedImage ( src , at ) ; g2 . dispose ( ) ; return dst ; }
target:  method to rotate an image through a given angle