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?
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.
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.
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 .
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With