Javafx 如何在圆中设置图像

Javafx 如何在圆中设置图像,javafx,geometry,Javafx,Geometry,我怎样才能在一个圆圈中设置一个图像。有没有更好的方法来设置带圆圈边框的图像?(尤其是windows 10登录屏幕上的图像框) 这就是你要找的 它用图像填充形状,因此您的代码可能如下所示 cir2.setFill(new ImagePattern(Image)); 测试代码 public void start(Stage primaryStage) { try { BorderPane root = new BorderPane(); root.set

我怎样才能在一个圆圈中设置一个图像。有没有更好的方法来设置带圆圈边框的图像?(尤其是windows 10登录屏幕上的图像框)

这就是你要找的

它用
图像
填充
形状
,因此您的代码可能如下所示

cir2.setFill(new ImagePattern(Image));

测试代码

 public void start(Stage primaryStage) {
    try {
        BorderPane root = new BorderPane();
        root.setPadding(new Insets(10));
        Scene scene = new Scene(root,400,400);
        Label l = new Label("SHAPE IMAGE OF MY SISTER");
        l.setFont(Font.font(Font.getFontNames().get(23), FontWeight.EXTRA_BOLD, 14));
        l.setAlignment(Pos.CENTER);
        l.setPrefWidth(Double.MAX_VALUE);
        root.setTop(l);
        ///////////////important code starts from here
        Circle cir2 = new Circle(250,250,120);
        cir2.setStroke(Color.SEAGREEN);
        Image im = new Image("https://juicylinksmag.files.wordpress.com/2016/02/juliet-ibrahim.jpg",false);
        cir2.setFill(new ImagePattern(im));
        cir2.setEffect(new DropShadow(+25d, 0d, +2d, Color.DARKSEAGREEN));
        //////////////important code ends here
        root.setCenter(cir2);
        primaryStage.setScene(scene);
        primaryStage.show();
    } catch(Exception e) {
        e.printStackTrace();
    }
}

更好的方法是什么?发帖然后提问。如果我没有提供关于我的问题的很多信息,我很抱歉。我所得到的只是一个空白的圆圈,可能是一个带阴影的圆圈的复制品。没有涉及图像。而且这只有4行代码。现在还不清楚你为什么要改进这个。
 public void start(Stage primaryStage) {
    try {
        BorderPane root = new BorderPane();
        root.setPadding(new Insets(10));
        Scene scene = new Scene(root,400,400);
        Label l = new Label("SHAPE IMAGE OF MY SISTER");
        l.setFont(Font.font(Font.getFontNames().get(23), FontWeight.EXTRA_BOLD, 14));
        l.setAlignment(Pos.CENTER);
        l.setPrefWidth(Double.MAX_VALUE);
        root.setTop(l);
        ///////////////important code starts from here
        Circle cir2 = new Circle(250,250,120);
        cir2.setStroke(Color.SEAGREEN);
        Image im = new Image("https://juicylinksmag.files.wordpress.com/2016/02/juliet-ibrahim.jpg",false);
        cir2.setFill(new ImagePattern(im));
        cir2.setEffect(new DropShadow(+25d, 0d, +2d, Color.DARKSEAGREEN));
        //////////////important code ends here
        root.setCenter(cir2);
        primaryStage.setScene(scene);
        primaryStage.show();
    } catch(Exception e) {
        e.printStackTrace();
    }
}