title: Java image rotation with AffineTransform outputs black image, but works well when resized
body: <p>I am just trying to rotate a JPG file by 90 degrees. However my code outputs image (<code>BufferedImage</code>) that is completely black.</p>
  
  <p>Here's the way to reproduce: (Download 3.jpg <strong><a href="http://dl.dropbox.com/u/1243397/3.jpg">here</a></strong>)</p>
  
  <pre><code>private static BufferedImage transform(BufferedImage originalImage) {
      BufferedImage newImage = null;
      AffineTransform tx = new AffineTransform();
      tx.rotate(Math.PI / 2, originalImage.getWidth() / 2, originalImage.getHeight() / 2);
  
      AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BICUBIC);
      newImage = op.filter(originalImage, newImage);
  
      return newImage;
  }
  
  public static void main(String[] args) throws Exception {
      BufferedImage bi = transform(ImageIO.read(new File(
              "3.jpg")));
      ImageIO.write(bi, "jpg", new File("out.jpg"));
  
  }
  </code></pre>
  
  <p>What's wrong here?</p>
  
  <p>(if I give this black output <code>BufferedImage</code> to a image resizer library, it gets resized well, original image is still there.)</p>