@@ -308,18 +308,23 @@ private static BufferedImage rotateImage(BufferedImage buffImage, double angle)
308
308
int width = buffImage .getWidth ();
309
309
int height = buffImage .getHeight ();
310
310
311
- int nWidth = (int ) Math .floor (( double ) width * cos + ( double ) height * sin );
312
- int nHeight = (int ) Math .floor (( double ) height * cos + ( double ) width * sin );
311
+ int nWidth = (int ) Math .floor (width * cos + height * sin );
312
+ int nHeight = (int ) Math .floor (height * cos + width * sin );
313
313
314
314
BufferedImage rotatedImage = new BufferedImage (nWidth , nHeight , BufferedImage .TYPE_INT_ARGB );
315
315
316
316
Graphics2D graphics = rotatedImage .createGraphics ();
317
+
318
+ graphics .setRenderingHint (RenderingHints .KEY_INTERPOLATION , RenderingHints .VALUE_INTERPOLATION_BILINEAR );
319
+ graphics .setRenderingHint (RenderingHints .KEY_RENDERING , RenderingHints .VALUE_RENDER_QUALITY );
320
+ graphics .setRenderingHint (RenderingHints .KEY_ANTIALIASING , RenderingHints .VALUE_ANTIALIAS_ON );
321
+
317
322
AffineTransform at = new AffineTransform ();
318
- at .translate ((nWidth - width ) / 2 , (nHeight - height ) / 2 );
319
- at .rotate (radian , (double ) (width / 2 ), (double ) (height / 2 ));
323
+ at .translate ((double ) (nWidth - width ) / 2 , (double ) (nHeight - height ) / 2 );
324
+ at .rotate (radian , width / 2.0 , height / 2.0 );
325
+
320
326
graphics .setTransform (at );
321
327
graphics .drawImage (buffImage , 0 , 0 , null );
322
- graphics .drawRect (0 , 0 , nWidth - 1 , nHeight - 1 );
323
328
graphics .dispose ();
324
329
325
330
return rotatedImage ;
0 commit comments