Java ImageIcon Scale scaleIcon(int width, int height, ImageIcon img)

Here you can find the source of scaleIcon(int width, int height, ImageIcon img)

Description

Scales the given image icon to the input width/height

License

Open Source License

Parameter

Parameter Description
width new width
height new height
img image icon to resize

Return

scaled image icon

Declaration

public static ImageIcon scaleIcon(int width, int height, ImageIcon img) 

Method Source Code

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

import javax.swing.*;
import java.awt.*;

public class Main {
    /**//from www.  j a v a2 s.  com
     * Scales the given image icon to the input width/height
     *
     * @param width  new width
     * @param height new height
     * @param img    image icon to resize
     * @return scaled image icon
     */
    public static ImageIcon scaleIcon(int width, int height, ImageIcon img) {
        return new ImageIcon(scaleImage(width, height, img.getImage()));
    }

    /**
     * Scales the given image to the input width/height
     *
     * @param width  new width
     * @param height new height
     * @param img    img to resize
     * @return scaled image
     */
    public static Image scaleImage(int width, int height, Image img) {
        return img.getScaledInstance(width, height, Image.SCALE_SMOOTH);
    }
}

Related

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