Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert JavaFX image To BufferedImage

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?

like image 949
Piet Jetse Avatar asked Feb 04 '14 00:02

Piet Jetse


People also ask

What is the difference between BufferedImage and image?

List, the difference between Image and BufferedImage is the same as the difference between List and LinkedList. Image is a generic concept and BufferedImage is the concrete implementation of the generic concept; kind of like BMW is a make of a Car. Show activity on this post. Image is an abstract class.

Which package is required to load images JavaFX?

Image class is used to load an image into a JavaFX application. This supports BMP, GIF, JPEG, and, PNG formats. JavaFX provides a class named javafx. scene.

Is ImageView a JavaFX node?

Class ImageView. The ImageView is a Node used for painting images loaded with Image class. This class allows resizing the displayed image (with or without preserving the original aspect ratio) and specifying a viewport into the source image for restricting the pixels displayed by this ImageView .


1 Answers

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);
like image 111
lukk Avatar answered Oct 13 '22 21:10

lukk