Java Utililty Methods ImageIcon Scale

List of utility methods to do ImageIcon Scale

Description

The list of methods to do ImageIcon Scale are organized into topic(s).

Method

ImageIconscaleIconTo(ImageIcon icon, int width, int height)
scale Icon To
Image image = icon.getImage().getScaledInstance(width, height, Image.SCALE_SMOOTH);
icon.setImage(image);
return icon;
ImageIconscaleImage(ImageIcon i, int x, int y)
scale Image
return new ImageIcon(i.getImage().getScaledInstance(x, y, Image.SCALE_SMOOTH));
ImageIconscaleImage(ImageIcon icon)
scale Image
Image img = icon.getImage();
Image newimg = img.getScaledInstance(444, 200, java.awt.Image.SCALE_SMOOTH);
ImageIcon newIcon = new ImageIcon(newimg);
return newIcon;
ImageIconscaleImage(ImageIcon src, int width, int height)
scale Image
return new ImageIcon(scaleImage(src.getImage(), width, height));
ImageIconscaleImageIcon(ImageIcon icon, float scale, int hints)
get a scaled instance of the input ImageIcon
if (icon == null)
    return null;
if (scale > 1.0f || scale <= 0.0f)
    throw new IllegalArgumentException("scale must be in (0, 1].");
int w = icon.getIconWidth();
int h = icon.getIconHeight();
return new ImageIcon(icon.getImage().getScaledInstance((int) (w * scale), (int) (h * scale), hints));
ImageIconscaleImageIcon(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();
if (height > newHeight) {
    height = newHeight;
if (width > newWidth) {
    width = newWidth;
...
ImageIconscaleImageIcon(ImageIcon icon, int w, int h)
scale Image Icon
Image img = icon.getImage();
return new ImageIcon(img.getScaledInstance(w, h, Image.SCALE_SMOOTH));
ImageIconscaleImageIcon(String filePath, double maxHeight)
scale Image Icon
ImageIcon icon = new ImageIcon(filePath);
double scaleFactor = maxHeight / icon.getIconHeight();
Image image = icon.getImage().getScaledInstance((int) (icon.getIconWidth() * scaleFactor), (int) maxHeight,
        Image.SCALE_SMOOTH);
icon.setImage(image);
return icon;
ImageIconscaleImageIconTo(ImageIcon source, int height, int width)
scale Image Icon To
return new ImageIcon(source.getImage().getScaledInstance(width, height, Image.SCALE_SMOOTH));