Here you can find the source of toImage(Icon icon)
public static Image toImage(Icon icon)
//package com.java2s; //License from project: Open Source License import java.awt.Graphics2D; import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import java.awt.Image; import java.awt.image.BufferedImage; import javax.swing.Icon; import javax.swing.ImageIcon; public class Main { public static Image toImage(Icon icon) { if (icon instanceof ImageIcon) return ((ImageIcon) icon).getImage(); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gd.getDefaultConfiguration(); BufferedImage image = gc.createCompatibleImage(icon.getIconWidth(), icon.getIconHeight()); Graphics2D g = image.createGraphics(); icon.paintIcon(null, g, 0, 0);//from w w w.j ava2s . com g.dispose(); return image; } }