【发布时间】:2020-04-12 03:56:29
【问题描述】:
有没有办法获取 JavaFX Parent 或 Scene 的像素的像素颜色/alpha 透明度?
例如,如何在(x,y) 处获取StackPane 的像素颜色?
在Java Swing there is a method、printAll,可以从中提取任意分量的像素。
但是我在 JavaFX 中找不到这样的方法。
编辑:@kleopatra 要求提供一个完整的生殖示例,所以这里是:
package helloworld;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class HelloWorld extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Hello World!");
Button btn = new Button();
btn.setText("Say 'Hello World'");
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("Hello World!");
}
});
StackPane root = new StackPane();
root.getChildren().add(btn);
primaryStage.setScene(new Scene(root, 300, 250));
primaryStage.show();
}
}
我如何获得root 的像素颜色,比如x,y?
【问题讨论】:
-
你需要获取颜色并使用Color#getOpacity
-
我如何获得颜色?