Convert JavaFX image To BufferedImage

Piet Jetse picture Piet Jetse · Feb 4, 2014 · Viewed 11.3k times · Source

I'm trying to convert an JavaFX Image(from ImageView) to an BufferedImage. I tried casting and stuff but nothing works. Can someone suggest how i should do this?

Answer

lukk picture lukk · Feb 4, 2014

Try your luck with SwingFXUtils. There is a method for that purpose:

BufferedImage fromFXImage(Image img, BufferedImage bimg)

You can call it with second parameter null, as it is optional (exists for memory reuse reason):

BufferedImage image = SwingFXUtils.fromFXImage(fxImage, null);