我正在我已经工作的Java Web应用程序中实现截图捕获。但是我遇到了屏幕截图的问题,因为整个屏幕都采用了图像:
正如您所看到的,这是整个屏幕,我只想用图形(白色区域)捕捉区域。我用来捕获这个屏幕的代码是:
public void captureGraphs() {
try {
Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
Robot robot = new Robot();
BufferedImage img = robot.createScreenCapture(new Rectangle(size));
File f = new File("C:/capture");
if (!f.exists()) {
f.mkdir();
}
File[] flist = f.listFiles();
for (File flist1 : flist) {
flist1.delete();
}
ImageIO.write(img, "JPG", new File("C:/capture/screenShot.jpg"));
System.out.println("Capture Successfull");
FacesContext.getCurrentInstance().addMessage(
null,
new FacesMessage(FacesMessage.SEVERITY_INFO,
"Successful!",
"You have successfully taken a snapshot. Thank You"));
} catch (HeadlessException e) {
System.out.println(e.getMessage());
} catch (AWTException e) {
System.out.println(e.getMessage());
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
有没有什么办法可以改变这段代码来捕捉中间部分只持有图表?