I need to draw the content of a component and all its subcomponents in a bitmap.
The following code works perfectly if i want to draw the entire component :
public void printComponent(Component c, String format, String filename) throws IOException {
// Create a renderable image with the same width and height as the component
BufferedImage image = new BufferedImage(c.getWidth(), c.getHeight(), BufferedImage.TYPE_INT_ARGB);
// Render the component and all its sub components
c.paintAll(image.getGraphics());
// Render the component and ignoring its sub components
c.paint(image.getGraphics());
// Save the image out to file
ImageIO.write(image, format, new File(filename));
}
but i didn’t find a way for drawing only a region of this component.
Any idea ?
You need to translate like this:
Full example with output: