Java Utililty Methods Icon to Image

List of utility methods to do Icon to Image

Description

The list of methods to do Icon to Image are organized into topic(s).

Method

ImageiconToImage(Icon icon)
Converts an Icon to an Image.
if (icon instanceof ImageIcon) {
    return ((ImageIcon) icon).getImage();
int w = icon.getIconWidth();
int h = icon.getIconHeight();
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gd.getDefaultConfiguration();
...
ImageiconToImage(Icon icon)
icon To Image
if (icon instanceof ImageIcon) {
    return ((ImageIcon) icon).getImage();
} else {
    int w = icon.getIconWidth();
    int h = icon.getIconHeight();
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gd = ge.getDefaultScreenDevice();
    GraphicsConfiguration gc = gd.getDefaultConfiguration();
...
BufferedImageiconToImage(Icon icon, Component comp)
icon To Image
int width = icon.getIconWidth();
int height = icon.getIconHeight();
if (width <= 0 || height <= 0) {
    return null;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = image.createGraphics();
icon.paintIcon(comp, g, 0, 0);
...
ImageiconToImage(Icon icon, int width, int height)
icon To Image
int w = icon.getIconWidth();
int h = icon.getIconHeight();
boolean sameSize = w == width && h == height;
if (icon instanceof ImageIcon && sameSize) {
    return ((ImageIcon) icon).getImage();
} else {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gd = ge.getDefaultScreenDevice();
...