答案 0 :(得分:5)
JPanel panel = ...
...
...
File yourFileHere = ...
...
...
BufferedImage img = new BufferedImage(panel.getWidth(), panel.getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics g = img.getGraphics();
panel.paint(g);
g.dispose();
try{
ImageIO.write(img, "png", yourFileHere);
}catch(IOException e){
e.printStackTrace();
}
答案 1 :(得分:1)
将由@Andrew Thompson描述并提供优秀示例here,但您可以通过阅读2D Graphics以及here
的示例来了解更多内容