Java Icon to BufferedImage getBufferedImageFromIcon(Icon icon)

Here you can find the source of getBufferedImageFromIcon(Icon icon)

Description

Creates a buffered image from an icon.

License

LGPL

Declaration

public static BufferedImage getBufferedImageFromIcon(Icon icon) 

Method Source Code


//package com.java2s;
/*//from   w w  w .  ja  v a2s  .  c o  m
 * IconUtils.java
 *
 * Copyright (c) 2009 JAM Development Team
 *
 * This package is distributed under the Lesser Gnu Public Licence (LGPL)
 *
 */

import javax.swing.*;

import java.awt.*;
import java.awt.image.*;

public class Main {
    /**
     * Creates a buffered image from an icon.
     */
    public static BufferedImage getBufferedImageFromIcon(Icon 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;
    }
}

Related

  1. getBufferedImage(Component comp, Icon icon)
  2. getBufferedImage(Icon icon)
  3. iconToBufferedImage(Icon icon)
  4. toBufferedImage(Icon icon)
  5. toBufferedImage(Icon icon, int x, int y)