Here you can find the source of iconToImage(Icon icon)
static public Image iconToImage(Icon icon)
//package com.java2s; // This copy of Ice is licensed to you under the terms described in the import java.awt.Image; import java.awt.image.BufferedImage; import java.awt.Graphics2D; import java.awt.GraphicsEnvironment; import javax.swing.Icon; import javax.swing.ImageIcon; public class Main { static public Image iconToImage(Icon icon) { if (icon instanceof ImageIcon) { return ((ImageIcon) icon).getImage(); } else {//w w w. j a v a2 s. c o m Graphics2D g = null; try { BufferedImage image = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration().createCompatibleImage(icon.getIconWidth(), icon.getIconHeight()); g = image.createGraphics(); icon.paintIcon(null, g, 0, 0); return image; } finally { if (g != null) { g.dispose(); } } } } }