ImageUtil { public static BufferedImage resizeImage(final BufferedImage image, final int newWidth, final int newHeight) { final Image resized = image.getScaledInstance(newWidth, newHeight, Image.SCALE_SMOOTH); return ImageUtil.bufferedImageFromImage(resized); }  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 resizeImage() { final BufferedImage larger = ImageUtil.resizeImage(oneByOne(BLACK), 46, 46); final BufferedImage smaller = ImageUtil.resizeImage(centeredPixel(WHITE), 1, 1); final BufferedImage stretched = ImageUtil.resizeImage(solidColor(30, 30, RED), 12, 34); assertEquals(46, larger.getWidth()); assertEquals(46, larger.getHeight()); assertEquals(1, smaller.getWidth()); assertEquals(1, smaller.getHeight()); assertEquals(12, stretched.getWidth()); assertEquals(34, stretched.getHeight()); final BufferedImage[] assertSameAfterResize = new BufferedImage[] { oneByOne(WHITE), oneByOne(GRAY), oneByOne(BLACK), oneByOne(RED), oneByOne(GREEN), oneByOne(BLUE), oneByOne(BLACK_HALF_TRANSPARENT), oneByOne(BLACK_TRANSPARENT), centeredPixel(WHITE), centeredPixel(GRAY), centeredPixel(BLACK), BLACK_PIXEL_TOP_LEFT, BLACK_PIXEL_TOP_RIGHT, BLACK_PIXEL_BOTTOM_LEFT, BLACK_PIXEL_BOTTOM_RIGHT, }; for (BufferedImage image : assertSameAfterResize) { assertTrue(bufferedImagesEqual(image, ImageUtil.resizeImage(image, image.getWidth(), image.getHeight()))); } }