Java ImageIcon Scale scaleIcon(ImageIcon icon, int size)

Here you can find the source of scaleIcon(ImageIcon icon, int size)

Description

scale Icon

License

Open Source License

Declaration

public static ImageIcon scaleIcon(ImageIcon icon, int size) 

Method Source Code


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

import java.awt.*;
import java.awt.image.BufferedImage;

import javax.swing.ImageIcon;

public class Main {
    public static ImageIcon scaleIcon(ImageIcon icon, int size) {
        return new ImageIcon(scaleIcon(icon.getImage(), size));
    }// w  ww  .jav  a  2  s  . c o  m

    public static BufferedImage scaleIcon(Image iconImage, int size) {
        BufferedImage newImage = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2 = newImage.createGraphics();
        try {
            g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
            g2.drawImage(iconImage, 0, 0, size, size, null);
        } finally {
            g2.dispose();
        }
        return newImage;
    }
}

Related

  1. rescaleImageIcon(ImageIcon image, int size)
  2. scale(ImageIcon icon, int maxWidth, int maxHeight)
  3. scale(ImageIcon icon, int newHeight, int newWidth)
  4. scale(ImageIcon original, int width, int height)
  5. scaleIcon(final ImageIcon icon)
  6. scaleIcon(int width, int height, ImageIcon img)
  7. scaleIconTo(ImageIcon icon, int width, int height)
  8. scaleImage(ImageIcon i, int x, int y)
  9. scaleImage(ImageIcon icon)