Here you can find the source of createScaledImage(Image inImage, int inWidth, int inHeight)
Parameter | Description |
---|---|
inImage | image to scale |
inWidth | width to scale to |
inHeight | height to scale to |
public static BufferedImage createScaledImage(Image inImage, int inWidth, int inHeight)
//package com.java2s; //License from project: Open Source License import java.awt.Graphics; import java.awt.Image; import java.awt.image.BufferedImage; import java.awt.image.ConvolveOp; import javax.swing.ImageIcon; public class Main { private static ConvolveOp CONVOLVER = null; /**//from www . ja va 2 s . com * Create a scaled and smoothed image according to the specified size * @param inImage image to scale * @param inWidth width to scale to * @param inHeight height to scale to * @return BufferedImage containing scaled result */ public static BufferedImage createScaledImage(Image inImage, int inWidth, int inHeight) { // create smaller image and force its loading Image smallerImage = inImage.getScaledInstance(inWidth, inHeight, Image.SCALE_SMOOTH); Image tempImage = new ImageIcon(smallerImage).getImage(); tempImage.getWidth(null); // create buffered image to do transform BufferedImage buffer = new BufferedImage(inWidth, inHeight, BufferedImage.TYPE_INT_RGB); // copy scaled picture into buffer Graphics buffG = buffer.getGraphics(); buffG.drawImage(smallerImage, 0, 0, inWidth, inHeight, null); buffG.dispose(); // clear variables smallerImage = null; tempImage = null; // smooth scaled image using a normalized 3x3 matrix - taking next neighbour buffer = CONVOLVER.filter(buffer, null); return buffer; } }