Reputation: 21
I'm working with JavaFx and i'm looking for an equivalent of the AWT BufferedImage
. I saw that I can used SwingFXUtils
to used an awt BufferedImage
with JavaFx but I don't want to used awt
.
In fact I'm looking for a structure to display a table of pixel witch is associated to a ColorModel
.
Does anybody know some equivalent with JavaFx ?
Thanks a lot.
Upvotes: 2
Views: 7273
Reputation: 27084
The closest you get to a BufferedImage
in JavaFX is javafx.scene.image.WritableImage
. It is a subclass of javafx.scene.image.Image
, and was introduced in JavaFX 2.2.
Depending on your use case, javafx.scene.canvas.Canvas
and javafx.scene.canvas.GraphicsContext
(similar to a Graphics2D
Java2D) might be a better fit.
To paint on a Canvas
node and get the contents in a WritableImage
, use (adapted from the Canvas
JavaDoc):
// Create canvas
Canvas canvas = new Canvas(250, 250);
GraphicsContext gc = canvas.getGraphicsContext2D();
// Paint on it
gc.setFill(Color.BLUE);
gc.fillRect(75, 75, 100, 100);
// NOTE: The canvas must be part of a Scene for the following to work properly, omitted for brevity
// Obtain a snapshot of the canvas
WritableImage image = canvas.snapshot(null, null);
See Working with Canvas from he JavaFX tutorials for more information.
Upvotes: 3