Writing javafx.scene.image.Image to file?

后端 未结 2 888
不思量自难忘°
不思量自难忘° 2020-12-09 04:52

How would I go about writing a javafx.scene.image.Image image to a file. I know you can use ImageIO on BufferedImages but is there any way to do it with a javafx Image?

2条回答
  •  悲哀的现实
    2020-12-09 05:09

    Just convert it to a BufferedImage first, using javafx.embed.swing.SwingFXUtils:

    Image image = ... ; // javafx.scene.image.Image
    String format = ... ;
    File file = ... ;
    ImageIO.write(SwingFXUtils.fromFXImage(image, null), format, file);
    

提交回复
热议问题