Here you can find the source of getScaledImage(Image srcImg, int w, int h)
Parameter | Description |
---|---|
srcImg | - source image to scale |
w | - desired width |
h | - desired height |
public static ImageIcon getScaledImage(Image srcImg, int w, int h)
//package com.java2s; //License from project: Open Source License import java.awt.Graphics2D; import java.awt.Image; import java.awt.RenderingHints; import java.awt.image.BufferedImage; import javax.swing.ImageIcon; public class Main { /**/*from w w w.j a va2 s . c o m*/ * Resizes an image using a Graphics2D object backed by a BufferedImage. * * @param srcImg - source image to scale * @param w - desired width * @param h - desired height * @return - the new resized image */ public static ImageIcon getScaledImage(Image srcImg, int w, int h) { BufferedImage resizedImg = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = resizedImg.createGraphics(); g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g2.drawImage(srcImg, 0, 0, w, h, null); g2.dispose(); return new ImageIcon(resizedImg); } }