Swing 显示良好JPanel保存为图片

在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();
}


版权声明:本文博客原创文章,博客,未经同意,不得转载。

posted @ 2015-07-24 15:38  blfshiye  阅读(318)  评论(0编辑  收藏  举报