ImageUtil { public static BufferedImage rotateImage(final BufferedImage image, final double theta) { AffineTransform transform = new AffineTransform(); transform.rotate(theta, image.getWidth() / 2.0, image.getHeight() / 2.0); AffineTransformOp transformOp = new AffineTransformOp(transform, AffineTransformOp.TYPE_BILINEAR); return transformOp.filter(image, null); }  static BufferedImage bufferedImageFromImage(final Image image); static BufferedImage toARGB(final Image image); static BufferedImage luminanceOffset(final Image rawImg, final int offset); static BufferedImage luminanceScale(final Image rawImg, final float percentage); static BufferedImage alphaOffset(final Image rawImg, final int offset); static BufferedImage alphaOffset(final Image rawImg, final float percentage); static BufferedImage grayscaleImage(final BufferedImage image); static BufferedImage resizeImage(final BufferedImage image, final int newWidth, final int newHeight); static BufferedImage resizeCanvas(final BufferedImage image, final int newWidth, final int newHeight); static BufferedImage rotateImage(final BufferedImage image, final double theta); static BufferedImage flipImage(final BufferedImage image, final boolean horizontal, final boolean vertical); static BufferedImage outlineImage(final BufferedImage image, final Color color); static BufferedImage outlineImage(final BufferedImage image, final Color color, final Boolean outlineCorners); static BufferedImage getResourceStreamFromClass(final Class c, final String path); static BufferedImage fillImage(final BufferedImage image, final Color color); static SpritePixels getImageSpritePixels(BufferedImage image, Client client); static IndexedSprite getImageIndexedSprite(BufferedImage image, Client client);  }
@Test public void rotateImage() { assertTrue(bufferedImagesEqual(BLACK_PIXEL_TOP_RIGHT, ImageUtil.rotateImage(BLACK_PIXEL_TOP_LEFT, Math.PI / 2))); assertTrue(bufferedImagesEqual(BLACK_PIXEL_BOTTOM_RIGHT, ImageUtil.rotateImage(BLACK_PIXEL_TOP_LEFT, Math.PI))); assertTrue(bufferedImagesEqual(BLACK_PIXEL_BOTTOM_LEFT, ImageUtil.rotateImage(BLACK_PIXEL_TOP_LEFT, Math.PI * 3 / 2))); assertTrue(bufferedImagesEqual(BLACK_PIXEL_TOP_LEFT, ImageUtil.rotateImage(BLACK_PIXEL_TOP_LEFT, Math.PI * 2))); final BufferedImage twoByOneLeft = new BufferedImage(2, 1, BufferedImage.TYPE_INT_ARGB); twoByOneLeft.setRGB(0, 0, BLACK.getRGB()); final BufferedImage twoByTwoRight = new BufferedImage(2, 1, BufferedImage.TYPE_INT_ARGB); twoByTwoRight.setRGB(1, 0, BLACK.getRGB()); final BufferedImage oneByTwoTop = new BufferedImage(2, 2, BufferedImage.TYPE_INT_ARGB); oneByTwoTop.setRGB(1, 0, new Color(0, 0, 0, 127).getRGB()); final BufferedImage oneByTwoBottom = new BufferedImage(2, 2, BufferedImage.TYPE_INT_ARGB); oneByTwoBottom.setRGB(0, 0, new Color(0, 0, 0, 127).getRGB()); oneByTwoBottom.setRGB(0, 1, BLACK.getRGB()); assertTrue(bufferedImagesEqual(oneByTwoTop, ImageUtil.rotateImage(twoByOneLeft, Math.PI / 2))); assertTrue(bufferedImagesEqual(twoByTwoRight, ImageUtil.rotateImage(twoByOneLeft, Math.PI))); assertTrue(bufferedImagesEqual(oneByTwoBottom, ImageUtil.rotateImage(twoByOneLeft, Math.PI * 3 / 2))); assertTrue(bufferedImagesEqual(twoByOneLeft, ImageUtil.rotateImage(twoByOneLeft, Math.PI * 2))); }