Java ImageIcon Create getIconImage(Icon icon)

Here you can find the source of getIconImage(Icon icon)

Description

get Icon Image

License

Open Source License

Return

an image for the specified icon.

Declaration

public static Image getIconImage(Icon icon) 

Method Source Code


//package com.java2s;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import javax.swing.Icon;
import javax.swing.ImageIcon;

public class Main {
    /**/* w w  w .j  av  a  2  s .c o m*/
     * @return an image for the specified icon.
     */
    public static Image getIconImage(Icon icon) {
        if (icon instanceof ImageIcon) {
            ImageIcon imageIcon = (ImageIcon) icon;
            return imageIcon.getImage();
        } else {
            Image image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
            Graphics2D g2 = (Graphics2D) image.getGraphics();
            icon.paintIcon(null, g2, 0, 0);

            icon = new ImageIcon(image);
            g2.dispose();

            return image;
        }
    }
}

Related

  1. createImageIcon(String resourcePath)
  2. createImageIcon(URL url)
  3. createImageIcon(URL url, String description, Integer w, Integer h)
  4. createImageIconJLabel(ClassLoader classloader, String path, String description, String text)
  5. createImageIcons(java.awt.Image... images)
  6. getIconImage(String path)
  7. toImageIcon(File file, int width, int height)
  8. toImageIcon(Icon icon)
  9. toImageIcon(URL resource, int width, int height)