Matt C
Matt C

Reputation: 147

Converting a ImageIcon array to a BufferedImage

I was wondering if there was a way of having a ImageIcon[] converted into a series of Buffered Image, I was thinking along the lines of something like this:

  public BufferedImage iconArrayToBufferedImage(ImageIcon[] icon){
    for (int i = 0; i < icon.length; i++) {
        BufferedImage screenShot = new BufferedImage(icon[i]);
    }


    return screenShot;

}

Upvotes: 1

Views: 2202

Answers (1)

Andrew Thompson
Andrew Thompson

Reputation: 168815

E.G. as seen in this answer.

BufferedImage bi = new BufferedImage(
    icon.getIconWidth(),
    icon.getIconHeight(),
    BufferedImage.TYPE_INT_RGB);
Graphics g = bi.createGraphics();
// paint the Icon to the BufferedImage.
icon.paintIcon(null, g, 0,0);
g.dispose();

For many icons, do that in a loop.

Upvotes: 2

Related Questions