1

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;

}
Matt C
  • 137
  • 1
  • 3
  • 15
  • Is your goal to layout the icons horizontally, vertically, or in a 2D layout? Or is your goal to create an array of buffered images, with one for each image icon? – FThompson Sep 21 '12 at 15:30

1 Answers1

2

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.

Community
  • 1
  • 1
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • That works, but would there be a way to concatenate the multiple images together, into a single BufferedImage? – Matt C Sep 24 '12 at 10:05
  • Sure, it only takes a little logic (make final image bigger, loop the small images) and painting the image parts at the right places (look at the arguments for `paintIcon`). – Andrew Thompson Sep 24 '12 at 23:44