/** * This method renders what would be in the pose area into the imageToPaintTo image argument. The * paintComponent method paints to a canvas (i.e. the screen), which this one is paints to an * image that can then be saved to a file * * @param imageToPaintTo The image we will paint what is in this canvas' pose area to. */ public void paintToImage(BufferedImage imageToPaintTo) { Graphics2D imageG2 = (Graphics2D) imageToPaintTo.getGraphics(); imageG2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); AnimatedSpriteEditor singleton = AnimatedSpriteEditor.getEditor(); PoseurStateManager poseurStateManager = singleton.getStateManager().getPoseurStateManager(); PoseurPose pose = poseurStateManager.getPose(); // FIRST LET'S PUT A TRANSPARENT BACKGROUND THE SIZE OF THE POSE Rectangle2D.Double transparentRect = new Rectangle2D.Double(0, 0, pose.getPoseWidth(), pose.getPoseHeight()); imageG2.setColor(TRANSPARENT_BACKGROUND_COLOR); imageG2.fill(transparentRect); imageG2.draw(transparentRect); // NOW LET'S DRAW ALL THE SHAPES ON TOP, BUT WE'LL // FAKE THE POSE AREA SO WE ONLY DRAW THE MIDDLE PART Rectangle2D.Double poseArea = new Rectangle2D.Double(0, 0, pose.getPoseWidth(), pose.getPoseHeight()); renderShapes(imageG2, poseArea); // ALL DONE, WE'VE JUST PAINTED TO THE IMAGE WHAT WE // WOULD NORMALLY DRAW INSIDE THE POSE AREA }