32 lines
984 B
Java
32 lines
984 B
Java
package nt.UI.util;
|
|
|
|
import java.awt.Graphics2D;
|
|
import java.awt.Image;
|
|
import java.awt.RenderingHints;
|
|
import java.awt.image.BufferedImage;
|
|
|
|
import javax.swing.Icon;
|
|
import javax.swing.ImageIcon;
|
|
|
|
public class IconResizer {
|
|
|
|
public static Icon resizeIcon(Icon icon, int width, int height) {
|
|
Icon newIcon = null;
|
|
if(icon != null && ImageIcon.class.isInstance(icon)
|
|
&& (icon.getIconHeight() != height && icon.getIconWidth() != width)) {
|
|
Image img = ((ImageIcon)icon).getImage();
|
|
BufferedImage bImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
|
Graphics2D g2d = bImg.createGraphics();
|
|
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
|
g2d.drawImage(img, 0, 0, width, height, null, null);
|
|
g2d.dispose();
|
|
newIcon = new ImageIcon(bImg);
|
|
}else {
|
|
newIcon = icon;
|
|
}
|
|
return newIcon;
|
|
}
|
|
|
|
}
|