The list of methods to do ImageIcon Scale are organized into topic(s).
ImageIcon
getScaledImageIcon(final String location, final int width, final int height) Get an image as a resource and create an ImageIcon
ImageIcon icon = null;
URL url = Thread.currentThread().getContextClassLoader().getResource(location);
if (url != null) {
icon = new ImageIcon(url);
icon = new ImageIcon(icon.getImage().getScaledInstance(width, height, Image.SCALE_SMOOTH));
return (icon);
ImageIcon
rescale(ImageIcon src, Dimension newMinSize, ImageObserver observer) Rescales an icon.
double widthRatio = newMinSize.getWidth() / (double) src.getIconWidth();
double heightRatio = newMinSize.getHeight() / (double) src.getIconHeight();
double scale = widthRatio > heightRatio ? widthRatio : heightRatio;
int w = (int) Math.round(scale * src.getIconWidth());
int h = (int) Math.round(scale * src.getIconHeight());
BufferedImage dst = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = dst.createGraphics();
g2.drawImage(src.getImage(), 0, 0, w, h, observer);
...
ImageIcon
rescaleImageIcon(ImageIcon image, int size) rescale Image Icon
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);
ImageIcon
scale(ImageIcon icon, int maxWidth, int maxHeight) scale
if (icon == null)
return null;
if (maxWidth >= icon.getIconWidth() && maxHeight >= icon.getIconHeight())
return icon;
int width = Math.min(maxWidth, icon.getIconWidth()), height = Math.min(maxHeight, icon.getIconHeight());
float widthFactor = (float) width / icon.getIconWidth(),
heightFactor = (float) height / icon.getIconHeight();
if (widthFactor < heightFactor) {
...
ImageIcon
scale(ImageIcon icon, int newHeight, int newWidth) Returns a scaled down image if the height or width is smaller than the image size.
Image img = icon.getImage();
int height = icon.getIconHeight();
int width = icon.getIconWidth();
boolean scaleHeight = height * newWidth > width * newHeight;
if (height > newHeight) {
if (width <= newWidth || scaleHeight) {
height = newHeight;
width = -1;
...
ImageIcon
scale(ImageIcon original, int width, int height) scale
if (original == null) {
throw new IllegalArgumentException("original image is NULL");
Image img = original.getImage();
Image newimg = img.getScaledInstance(width, height, java.awt.Image.SCALE_SMOOTH);
return new ImageIcon(newimg);
Icon
scaleIcon(final ImageIcon icon) Returns a scaled icon based on the reduced font size
int scaledWidth = (int) Math.floor(icon.getIconWidth() * growthPercentage);
int scaledHeight = (int) Math.floor(icon.getIconHeight() * growthPercentage);
Image scaledInstance = icon.getImage().getScaledInstance(scaledWidth, scaledHeight,
java.awt.Image.SCALE_SMOOTH);
return new ImageIcon(scaledInstance);