我正在尝试使用javaFX保存当前场景的屏幕截图。
saveMenuItem.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent t) {
WritableImage image = scene.snapshot(new SnapshotParameters(), null);
// TODO: probably use a file chooser here
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Save Image");
File file = fileChooser.showSaveDialog(primaryStage);
if(file != null)
{
try {
ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", file);
}
catch (IOException e) {
System.out.println("Couldn't Save.");
}
}
}
});
但是我的编译器NetBeans IDE 8.1发出错误:
incompatible types: SnapshotParameters cannot be converted to Callback<SnapshotResult, Void>
有人能告诉我我做错了吗?
答案 0 :(得分:0)
你的编译器是对的。一个场景就没有像你试图调用的方法。只需使用
WritableImage image = scene.snapshot(null);