protected static BufferedImage createImage(JComponent component,Rectangle region) throws IOException {
  boolean opaqueValue=component.isOpaque();
  component.setOpaque(true);
  BufferedImage image=new BufferedImage(region.width,region.height,BufferedImage.TYPE_INT_RGB);
  Graphics2D g2d=image.createGraphics();
  g2d.translate(-region.getX(),-region.getY());
  component.paint(g2d);
  g2d.dispose();
  component.setOpaque(opaqueValue);
  return image;
}

protected static BufferedImage createImage ( JComponent component , Rectangle region ) throws IOException { boolean opaqueValue = component . isOpaque ( ) ; component . setOpaque ( true ) ; BufferedImage image = new BufferedImage ( region . width , region . height , BufferedImage . TYPE_INT_RGB ) ; Graphics2D g2d = image . createGraphics ( ) ; g2d . translate ( - region . getX ( ) , - region . getY ( ) ) ; component . paint ( g2d ) ; g2d . dispose ( ) ; component . setOpaque ( opaqueValue ) ; return image ; }
utility method to create an image of a region of the given component
