Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to get pixel data from a JavaFX Canvas?

Tags:

java

javafx-2

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.

like image 622
Troy Squillaci Avatar asked Sep 29 '14 03:09

Troy Squillaci


1 Answers

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.

like image 80
Troy Squillaci Avatar answered Oct 21 '22 23:10

Troy Squillaci