List of usage examples for java.awt.image BufferedImageOp filter
public BufferedImage filter(BufferedImage src, BufferedImage dest);
From source file:ucar.unidata.idv.ui.ImageGenerator.java
/** * Scale the given {@code source} {@link Image}. * * @param source Source image./*from ww w . jav a2 s .c om*/ * @param width New width. * @param height New height. * * @return Scaled {@code source} image (uses bilinear interpolation). */ public static BufferedImage getScaledImage(Image source, int width, int height) { // convert the given Image into a BufferedImage if needed--makes things a // little easier. BufferedImage image; if (source instanceof BufferedImage) { image = (BufferedImage) source; } else { image = new BufferedImage(source.getWidth(null), source.getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics2D g = image.createGraphics(); g.drawImage(source, 0, 0, null); g.dispose(); } int imageWidth = image.getWidth(); int imageHeight = image.getHeight(); double scaleX = (double) width / imageWidth; double scaleY = (double) height / imageHeight; AffineTransform scaleTransform = AffineTransform.getScaleInstance(scaleX, scaleY); BufferedImageOp op = new AffineTransformOp(scaleTransform, AffineTransformOp.TYPE_BILINEAR); return op.filter(image, new BufferedImage(width, height, image.getType())); }