Here you can find the source of getScaledImage(Image imagen, double scaleW, double scaleH)
public static BufferedImage getScaledImage(Image imagen, double scaleW, double scaleH)
//package com.java2s; //License from project: Open Source License import java.awt.*; import java.awt.geom.AffineTransform; import java.awt.image.*; import javax.swing.*; public class Main { /**//from ww w. ja va 2 s. com * Obtiene una imagen escalada */ public static BufferedImage getScaledImage(Image imagen, double scaleW, double scaleH) { BufferedImage bi = toBufferedImage(imagen); int w = (int) (bi.getWidth() * scaleW); int h = (int) (bi.getHeight() * scaleH); bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = bi.createGraphics(); g2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); AffineTransform at = AffineTransform.getScaleInstance(scaleW, scaleH); g2.drawRenderedImage(toBufferedImage(imagen), at); g2.dispose(); return bi; } /** * Convierte un objeto Image a un BufferedImage * * @param img El objeto Image a convertir * @return El BufferedImage obtenido */ public static BufferedImage toBufferedImage(Image img) { if (img instanceof BufferedImage) { return (BufferedImage) img; } // Crea un buffered image con trasparencia BufferedImage bimage = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB); // Dibuja la imagen en el buffered image Graphics2D bGr = bimage.createGraphics(); bGr.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); bGr.drawImage(img, 0, 0, null); bGr.dispose(); // Retorna el buffered image return bimage; } /** * Obtiene el ancho de una Image */ public static int getWidth(Image imagen) { int width = new ImageIcon(imagen).getIconWidth(); return width; } /** * Obtiene el ancho de un IconImage */ public static int getWidth(ImageIcon imagen) { return imagen.getIconWidth(); } /** * Obtiene el alto de una Image */ public static int getHeight(Image imagen) { int height = new ImageIcon(imagen).getIconHeight(); return height; } /** * Obtiene el alto de un IconImage */ public static int getHeight(ImageIcon imagen) { return imagen.getIconHeight(); } }