简体   繁体   English

从JavaFX Canvas获取像素数据的最佳方法?

[英]Best way to get pixel data from a JavaFX Canvas?

Is it possible to get ARGB pixel data from a javafx.scene.canvas.Canvas ? 是否可以从javafx.scene.canvas.Canvas获取ARGB像素数据? 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. 我知道javafx.scene.image.Image提供了一个PixelReader来执行此操作,但我想尽可能直接从画布中获取这些数据。

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 . 由于Canvas扩展了Node ,它继承了Node.snapshot()方法,该方法将画布的当前状态保存到WritableImage Since WritableImage extends Image , I can get the PixelReader from the WritableImage and read the pixel data. 由于WritableImage扩展了Image ,我可以从WritableImage获取PixelReader并读取像素数据。 This may not be the most optimal solution, but it works for my application. 这可能不是最佳解决方案,但它适用于我的应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM