title: Black area using java 2D graphics rotation?
body: <p>I'll start of by showing examples of what's wrong then I'll explain how, and finally I'll ask my question.</p>
  
  <p>This is the picture I want to rotate.</p>
  
  <p><img src="https://i.stack.imgur.com/0ZWRu.png" alt="Just and example picture for stackoverflow"></p>
  
  <p>I am rotating it 90 degrees and 270 degrees, on multiple occasions and then combining<br>those into a big buffered-image.</p>
  
  <p>The code I am using to rotate a single bufferedImage is this:<br></p>
  
  <pre><code>public static BufferedImage rotate(BufferedImage img, int angle) {  
      int w = img.getWidth();  
      int h = img.getHeight();  
  
      BufferedImage dimg = new BufferedImage(w, h, img.getType());
  
      Graphics2D g = dimg.createGraphics();
      g.rotate(Math.toRadians(angle), w/2, h/2);  
      g.drawImage(img, null, 0, 0);  
      return dimg;  
  }
  </code></pre>
  
  <p>The out come of the rotation looks something like this.<br></p>
  
  <p><img src="https://i.stack.imgur.com/FA3Fq.png" alt="Rotation with native width and height"></p>
  
  <p>The reason those black bars are these is because in the code you can clearly see I create a separate buffered-image which will be the final image.<br><br>
  Which uses the original width and hight, since the image is rotated the with and height switch so I compensated for this by changing <code>BufferedImage dimg = new BufferedImage(w, h, img.getType());</code> to <code>BufferedImage dimg = new BufferedImage(h, w, img.getType());</code>.<br><br>
  I though it would be logical that this would solve my problem.<br>
  But I was wrong now the rotational outcome is this.<br></p>
  
  <p><img src="https://i.stack.imgur.com/EpO6s.png" alt="rotation with with and height switch">
  So from this point on is where I have no clue why it's doing this.<br>
  I might just be overlooking a tiny thing, or it's a common error even though I can't find <br>any instance of this occurring.<br>
  <br>
  So here is my question to you, why does it do this? And how do I fix this.</p>