Here you can find the source of performResize(BufferedImage source, int newWidth, int newHeight)
Parameter | Description |
---|---|
source | the source image. |
newWidth | the new image width. |
newHeight | the new image height. |
public static BufferedImage performResize(BufferedImage source, int newWidth, int newHeight)
//package com.java2s; /******************************************************************************* * Copyright (c) 2014 Black Rook Software * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Lesser Public License v2.1 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html ******************************************************************************/ import java.awt.AlphaComposite; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.image.BufferedImage; public class Main { /**/*from w ww . j a va 2 s . c o m*/ * Resizes an image using nearest filtering. * @param source the source image. * @param newWidth the new image width. * @param newHeight the new image height. */ public static BufferedImage performResize(BufferedImage source, int newWidth, int newHeight) { BufferedImage out = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = out.createGraphics(); g2d.setComposite(AlphaComposite.Src); g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); g2d.drawImage(source, 0, 0, newWidth, newHeight, null); g2d.dispose(); return out; } }