Troy Squillaci
Troy Squillaci

Reputation: 405

Best way to get pixel data from a JavaFX Canvas?

Is it possible to get ARGB pixel data from a javafx.scene.canvas.Canvas? I am aware that javafx.scene.image.Image provides a PixelReader for performing this operation but I would like to get this data directly from the canvas if possible.

Upvotes: 14

Views: 3383

Answers (1)

Troy Squillaci
Troy Squillaci

Reputation: 405

I believe I've found a solution. Since Canvas extends Node, it inherits the Node.snapshot() method which saves the current state of the canvas to a WritableImage. Since WritableImage extends Image, I can get the PixelReader from the WritableImage and read the pixel data. This may not be the most optimal solution, but it works for my application.

Upvotes: 9

Related Questions