我有一个从主监视器截取的图像,因此我想将其添加到Java FX ImageView:
ImageView
@FXML protected ImageView screenshot() throws AWTException, IOException { Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()); BufferedImage capture = new Robot().createScreenCapture(screenRect); ImageView imageView = new ImageView(); Image image = capture; //Error imageView.setImage(image); return imageView; }
我正在尝试将设置为BufferedImage capture,javafx.scene.image.Image image但是类型不兼容,也无法强制转换。我该如何纠正?
BufferedImage capture
javafx.scene.image.Image image
您可以使用
Image image = SwingFXUtils.toFXImage(capture, null);