Java ImageIcon Scale rescaleImageIcon(ImageIcon image, int size)

Here you can find the source of rescaleImageIcon(ImageIcon image, int size)

Description

rescale Image Icon

License

LGPL

Declaration

public static ImageIcon rescaleImageIcon(ImageIcon image, int size) 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;

public class Main {
    public static ImageIcon rescaleImageIcon(ImageIcon image, int size) {
        final BufferedImage img = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
        final Graphics2D g2d = img.createGraphics();
        g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
        final Image cursorImage = image.getImage();
        g2d.drawImage(cursorImage, new AffineTransform((double) size / cursorImage.getWidth(null), 0, 0,
                (double) size / cursorImage.getHeight(null), 0, 0), null);
        return new ImageIcon(img);
    }/*from  w  ww. java  2s  . c  o  m*/
}

Related

  1. getScaledImageIcon(final String location, final int width, final int height)
  2. getScaledImageIconHeight(ImageIcon ii, int h, boolean incr)
  3. rescale(ImageIcon src, Dimension newMinSize, ImageObserver observer)
  4. scale(ImageIcon icon, int maxWidth, int maxHeight)
  5. scale(ImageIcon icon, int newHeight, int newWidth)
  6. scale(ImageIcon original, int width, int height)
  7. scaleIcon(final ImageIcon icon)