All pastes #250117 Raw Edit

Miscellany

public text v1 · immutable
#250117 ·published 2006-11-16 17:02 UTC
rendered paste body
     public void saveComponentAsPNG(Component myComponent) {
       Dimension size = myComponent.getSize();
       BufferedImage myImage = 
         new BufferedImage(size.width, size.height,
         BufferedImage.TYPE_INT_RGB);
       Graphics2D g2 = myImage.createGraphics();
       myComponent.paint(g2);
       try {
            FileOutputStream file = new FileOutputStream("/sprites2/" + number + ".png", false);
            ImageIO.write(myImage, "png", file);
			number++;
        } catch (IOException e) {
            System.out.println(e.toString());
       } catch (Exception e) {
         System.out.println(e); 
       }
     }