Here is a code for resizing image using Graphics2D.
I also put bunch of rendering hints in the example code.
Hope it helps for your understanding.
I also put bunch of rendering hints in the example code.
Hope it helps for your understanding.
private static BufferedImage resize(BufferedImage image, int width, int height) { BufferedImage shrinkImage = new BufferedImage(width,height, image.getType()); Graphics2D g2d = shrinkImage.createGraphics(); // rendering hints g2d.setRenderingHint(KEY_ALPHA_INTERPOLATION, VALUE_ALPHA_INTERPOLATION_QUALITY); g2d.setRenderingHint(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON); g2d.setRenderingHint(KEY_COLOR_RENDERING, VALUE_COLOR_RENDER_QUALITY); g2d.setRenderingHint(KEY_DITHERING, VALUE_DITHER_ENABLE); g2d.setRenderingHint(KEY_TEXT_ANTIALIASING, VALUE_TEXT_ANTIALIAS_ON); g2d.setRenderingHint(KEY_RENDERING, VALUE_RENDER_QUALITY); g2d.setRenderingHint(KEY_INTERPOLATION, VALUE_INTERPOLATION_BILINEAR); g2d.setRenderingHint(KEY_FRACTIONALMETRICS, VALUE_FRACTIONALMETRICS_ON); g2d.setRenderingHint(KEY_STROKE_CONTROL, VALUE_STROKE_NORMALIZE); // draw image g2d.drawImage(image, 0, 0, width, height, null); return shrinkImage; }
コメント