get Scaled Image Icon - Java 2D Graphics

Java examples for 2D Graphics:BufferedImage Scale

Description

get Scaled Image Icon

Demo Code


//package com.java2s;

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

public class Main {
    public static ImageIcon getScaledImageIcon(ImageIcon imageIcon,
            int width, int height, int scale) {
        ImageIcon image = null;/*from   w  w w  .j  ava 2s  . c o  m*/
        try {
            if (imageIcon != null) {
                Image img = imageIcon.getImage().getScaledInstance(width,
                        height, scale);
                if (img != null)
                    image = new ImageIcon(img);
            }
        } catch (Throwable ex) {
            System.out.println("Could not scale ImageIcon");
        }
        return image;
    }
}

Related Tutorials