Guest User

Untitled

a guest
Aug 19th, 2019
89
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @FXML
  2. protected ImageView screenshot() throws AWTException, IOException {
  3. Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
  4. BufferedImage capture = new Robot().createScreenCapture(screenRect);
  5. ImageView imageView = new ImageView();
  6. Image image = capture; //Error
  7. imageView.setImage(image);
  8. return imageView;
  9. }
  10.  
  11. Image image = SwingFXUtils.toFXImage(capture, null);
  12.  
  13. private static Image convertToFxImage(BufferedImage image) {
  14. WritableImage wr = null;
  15. if (image != null) {
  16. wr = new WritableImage(image.getWidth(), image.getHeight());
  17. PixelWriter pw = wr.getPixelWriter();
  18. for (int x = 0; x < image.getWidth(); x++) {
  19. for (int y = 0; y < image.getHeight(); y++) {
  20. pw.setArgb(x, y, image.getRGB(x, y));
  21. }
  22. }
  23. }
  24.  
  25. return new ImageView(wr).getImage();
  26. }
RAW Paste Data