Java Utililty Methods Icon to BufferedImage

List of utility methods to do Icon to BufferedImage

Description

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

Method

BufferedImagegetBufferedImage(Component comp, Icon icon)
get Buffered Image
if (icon instanceof ImageIcon) {
    Image img = ((ImageIcon) icon).getImage();
    if (img instanceof BufferedImage) {
        return (BufferedImage) img;
return createImage(comp, icon);
BufferedImagegetBufferedImage(Icon icon)
get Buffered Image
if (icon instanceof BufferedImage) {
    return (BufferedImage) icon;
BufferedImage bimage = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(),
        BufferedImage.TYPE_INT_ARGB);
Graphics2D g = bimage.createGraphics();
g.addRenderingHints(new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY));
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
...
BufferedImagegetBufferedImageFromIcon(Icon icon)
Creates a buffered image from an icon.
BufferedImage buffer = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(),
        BufferedImage.TYPE_INT_ARGB);
Graphics g = buffer.getGraphics();
icon.paintIcon(new JLabel(), g, 0, 0);
g.dispose();
return buffer;
BufferedImageiconToBufferedImage(Icon icon)
icon To Buffered Image
BufferedImage bi = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_RGB);
Graphics g = bi.createGraphics();
g.setColor(Color.WHITE);
g.fillRect(0, 0, icon.getIconWidth(), icon.getIconHeight());
icon.paintIcon(null, g, 0, 0);
return bi;
BufferedImagetoBufferedImage(Icon icon)
to Buffered Image
BufferedImage result = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(),
        BufferedImage.TYPE_INT_ARGB);
icon.paintIcon(null, result.createGraphics(), 0, 0);
return result;
BufferedImagetoBufferedImage(Icon icon, int x, int y)

Converts the given Icon into a BufferedImage .

if (icon != null) {
    Graphics2D g = null;
    try {
        BufferedImage image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(),
                Transparency.TRANSLUCENT);
        g = image.createGraphics();
        icon.paintIcon(null, g, x, y);
        return image;
...