Java BufferedImage Resize imageResize(BufferedImage image, int width, int height)

Here you can find the source of imageResize(BufferedImage image, int width, int height)

Description

Code taken from a stackoverflow answer http://stackoverflow.com/a/14550112/1696114

License

Open Source License

Parameter

Parameter Description
image a parameter

Return

a resized bufferedimage

Declaration

public static BufferedImage imageResize(BufferedImage image, int width, int height) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;

public class Main {
    /**//from   w ww  . jav  a 2  s .c  o m
     * Code taken from a stackoverflow answer http://stackoverflow.com/a/14550112/1696114
     * @param image
     * @param width: new width for the image.
     * @param height: new height for the image.
     * @return a resized bufferedimage
     */
    public static BufferedImage imageResize(BufferedImage image, int width, int height) {
        BufferedImage bi = new BufferedImage(width, height, BufferedImage.TRANSLUCENT);
        Graphics2D g2d = (Graphics2D) bi.createGraphics();
        g2d.addRenderingHints(
                new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY));
        g2d.drawImage(image, 0, 0, width, height, null);
        g2d.dispose();
        return bi;
    }
}

Related

  1. downsizeImage(Image imgSource, int w, int h)
  2. fitImage(JLabel label, BufferedImage image)
  3. getResizedImage(BufferedImage image)
  4. getResizeFactor(BufferedImage source, int maxWidth, int maxHeight)
  5. linearResizeImage(BufferedImage origin, int width, int height)
  6. resizeToContainer(BufferedImage imagen, int wCont, int hCont)