title: Rotate a buffered image in Java
body: <p>I am trying to rotate a buffered image in java. Here is the code I am using:</p>
  <pre class="lang-java prettyprint-override"><code>public static BufferedImage rotate(BufferedImage bimg, double angle) {
      int w = bimg.getWidth();
      int h = bimg.getHeight();
      Graphics2D graphic = bimg.createGraphics();
      graphic.rotate(Math.toRadians(angle), w / 2, h / 2);
      graphic.drawImage(bimg, null, 0, 0);
      graphic.dispose();
      return bimg;
  }
  </code></pre>
  <p>I have looked a numerous stack overflow questions and answers on this topic and not been able to figure out why the image is chopped up the way it is when I try to rotate it. Here is an example showing a loaded image:
  <a href="https://i.stack.imgur.com/qnZfy.png" rel="nofollow noreferrer">loaded image</a></p>
  <p>After I click the rotate button which calls the above function with the buffered image and a 90.0 for the angle:
  <a href="https://i.stack.imgur.com/4Euz7.png" rel="nofollow noreferrer">chopped up image</a></p>
  <p>Can someone help me understand what is happening and how to fix it?</p>