public static BufferedImage getScaledInstance(BufferedImage image, int targetWidth, int targetHeight) {
        int type = (image.getTransparency() == Transparency.OPAQUE)
                ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB;
        BufferedImage tmp = new BufferedImage(targetWidth, targetHeight, type);
        Graphics2D g2 = tmp.createGraphics();
        g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
        g2.drawImage(image, 0, 0, targetWidth, targetHeight, null);
        g2.dispose();
        return tmp;
    }
public static BufferedImage getScaledInstance ( BufferedImage image , int targetWidth , int targetHeight ) { int type = ( image . getTransparency ( ) == Transparency . OPAQUE ) ? BufferedImage . TYPE_INT_RGB : BufferedImage . TYPE_INT_ARGB ; BufferedImage tmp = new BufferedImage ( targetWidth , targetHeight , type ) ; Graphics2D g2 = tmp . createGraphics ( ) ; g2 . setRenderingHint ( RenderingHints . KEY_INTERPOLATION , RenderingHints . VALUE_INTERPOLATION_BICUBIC ) ; g2 . drawImage ( image , 0 , 0 , targetWidth , targetHeight , null ) ; g2 . dispose ( ) ; return tmp ; }
Convenience method that returns a scaled instance of the provided
{@code BufferedImage}.

@param image the original image to be scaled
@param targetWidth the desired width of the scaled instance, in pixels
@param targetHeight the desired height of the scaled instance, in pixels
@return a scaled version of the original {@code BufferedImage}