截取JPanel的部分内容并保存为图片

BufferedImage image = new BufferedImage(1200,60, BufferedImage.TYPE_INT_RGB); //截取大小
Graphics2D g2 = image.createGraphics(); 
g2.translate(-1200, -60); // 截取起点
jpanel.paint(g2); // instead of just paint(g2); 

ImageIO.write(image, "jpeg",
new java.io.File("a file.jpg"));

你可能感兴趣的:(截取JPanel的部分内容并保存为图片)