次のメソッドを使用して、非軽量コンポーネントから BufferedImage を取得しようとしましたが、黒い画像を取得したため、機能しませんでした。渡したコンポーネントは、JDIC からの WebBrowser オブジェクトであり、非軽量コンポーネントです。 :
public static BufferedImage getComponentImage(Component aComponent,Rectangle region) throws IOException
{
BufferedImage image= new BufferedImage(aComponent.getWidth(),aComponent.getHeight(),BufferedImage.TYPE_INT_RGB);
Graphics2D g2d=image.createGraphics();
SwingUtilities.paintComponent(g2d,aComponent,aComponent.getParent(),region);
g2d.dispose();
/*
Graphics g = image.getGraphics();
aComponent.paint(g);
// aComponent.paintAll(g);
// SwingUtilities.paintComponent(g,aComponent,aComponent.getParent(),region);
g.dispose();
*/
return image;
}
コメントの行も試しましたが、どちらも機能しませんでした。Java で非軽量コンポーネントからBufferedImageをキャプチャする方法