Here you can find the source of getResizedImage(Image originalImage, Dimension newSize)
Parameter | Description |
---|---|
originalImage | the original image |
newSize | Dimension the size to which to pad/crop. |
public static BufferedImage getResizedImage(Image originalImage, Dimension newSize)
//package com.java2s; import java.awt.Dimension; import java.awt.Graphics2D; import java.awt.Image; import java.awt.image.BufferedImage; public class Main { /**// w ww .j a v a2 s. c o m * Get a resized image. * The original image will appear in the resized image, but will be padded or cropped as appropriate. * @param originalImage the original image * @param newSize Dimension the size to which to pad/crop. * @return BufferedImage the resulting image. */ public static BufferedImage getResizedImage(Image originalImage, Dimension newSize) { // construct the buffered image BufferedImage bImage = new BufferedImage(newSize.width, newSize.height, BufferedImage.TYPE_INT_ARGB); // obtain its graphics Graphics2D g2d = bImage.createGraphics(); // draw the original image into the new BufferedImage. g2d.drawImage(originalImage, null, null); // dispose the graphics object g2d.dispose(); return bImage; } }