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

ImageiconImage(Icon icon)
Transforms icon into an image.
if (icon instanceof ImageIcon)
    return ((ImageIcon) icon).getImage();
return null;
ImageiconToImage(@Nonnull Component context, @Nullable final Icon icon)
icon To Image
if (icon instanceof ImageIcon) {
    return ((ImageIcon) icon).getImage();
final int width = icon == null ? 16 : icon.getIconWidth();
final int height = icon == null ? 16 : icon.getIconHeight();
final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
if (icon != null) {
    final Graphics g = image.getGraphics();
...
ImageiconToImage(Icon icon)
icon To Image
if (icon instanceof ImageIcon) {
    return ((ImageIcon) icon).getImage();
BufferedImage image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(),
        BufferedImage.TYPE_INT_RGB);
icon.paintIcon(null, image.getGraphics(), 0, 0);
return image;
ImageiconToImage(Icon icon)
icon To Image
if (icon instanceof ImageIcon) {
    return ((ImageIcon) icon).getImage();
} else {
    Graphics2D g = null;
    try {
        BufferedImage image = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
                .getDefaultConfiguration().createCompatibleImage(icon.getIconWidth(), icon.getIconHeight());
        g = image.createGraphics();
...
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)
Converts a Icon into a BufferedImage
BufferedImage image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(),
        BufferedImage.TYPE_INT_RGB);
Graphics g = image.createGraphics();
icon.paintIcon(null, g, 0, 0);
g.dispose();
return image;
BufferedImageiconToImage(Icon icon)
Convert the given icon to an image.
BufferedImage ret = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(),
        BufferedImage.TYPE_INT_RGB);
icon.paintIcon(new JLabel(), ret.createGraphics(), 0, 0);
return ret;
ImageiconToImage(Icon icon)
icon To Image
if (icon instanceof ImageIcon) {
    return ((ImageIcon) icon).getImage();
} else {
    int w = icon.getIconWidth();
    int h = icon.getIconHeight();
    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice device = env.getDefaultScreenDevice();
    GraphicsConfiguration config = device.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();
...
ImageiconToImage(Icon icon)
icon To Image
if (icon instanceof ImageIcon) {
    return ((ImageIcon) icon).getImage();
} else {
    BufferedImage image = createCompatibleTranslucentImage(icon.getIconWidth(), icon.getIconHeight());
    Graphics2D g = image.createGraphics();
    icon.paintIcon(null, g, 0, 0);
    g.dispose();
    return image;
...