在JFrame中添加如下代码
//自己的JPanel
DrawPanel drawPanel = new DrawPanel(list, width, height, start, end);
// 必须要有大小
drawPanel.setSize(width, height);
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = image.createGraphics();
drawPanel.paint(g2);
try {
ImageIO.write(image, "jpeg", new File("jpanel.jpg"));
} catch (IOException e) {
e.printStackTrace();
}
Swing 将显示好的JPanel保存为一张图片,布布扣,bubuko.com
时间: 2024-10-15 06:57:19