Here you can find the source of toBufferedImage(Icon icon)
public static BufferedImage toBufferedImage(Icon icon)
//package com.java2s; //License from project: Open Source License import java.awt.Graphics2D; import java.awt.Image; import java.awt.image.BufferedImage; import javax.swing.Icon; public class Main { public static BufferedImage toBufferedImage(Image i) { BufferedImage result = new BufferedImage(i.getWidth(null), i.getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics2D g = result.createGraphics(); g.drawImage(i, 0, 0, null);/*w w w . ja v a 2 s . c o m*/ g.dispose(); return result; } public static BufferedImage toBufferedImage(Icon icon) { BufferedImage result = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); icon.paintIcon(null, result.createGraphics(), 0, 0); return result; } }