Equivalent of BufferedImage (java awt) on JavaFx


Question

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.

1
2
6/25/2014 2:12:51 PM

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.

3
6/26/2014 8:34:16 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon