Java Icon to BufferedImage toBufferedImage(Icon icon)

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

Description

to Buffered Image

License

Open Source License

Declaration

public static BufferedImage toBufferedImage(Icon icon) 

Method Source Code

//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;
    }
}

Related

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