我制作了屏幕快照并尝试获取图像的一部分,当我尝试将其保存到文件时它不起作用。很乐意得到任何建议
Rectangle Rect = new Rectangle(10, 10, 50, 50);
File file = new File("D:\\output.png");
RenderedImage renderedImage = SwingFXUtils.fromFXImage(browser.snapshot(null, null), null);
try {
ImageIO.write((RenderedImage) renderedImage.getData(Rect),"png",file);
} catch (IOException ex { Logger.getLogger(JavaFXApplication3.class.getName()).log(Level.SEVERE, null, ex);
}
所以在这里我终于得到了它并且它有效
File file = new File("D:\\output.png");
BufferedImage image = SwingFXUtils.fromFXImage(browser.snapshot(null, null), null);
try {
ImageIO.write(image.getSubimage(100, 100, 50, 50) , "png", file);
} catch (IOException ex) {
Logger.getLogger(JavaFXApplication3.class.getName()).log(Level.SEVERE, null, ex);
}