Компонент Java Paint в растровое изображение

Мне нужно нарисовать содержимое компонента и всех его подкомпонентов в растровом изображении. Следующий код отлично работает, если я хочу нарисовать весь компонент:

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));

}

, но я не нашел способа нарисовать только область этого компонента. Есть идеи?

6
задан Arutha 22 November 2010 в 11:59
поделиться