【问题标题】:How to set an image in a circle如何将图像设置为圆形
【发布时间】:2017-02-08 14:50:31
【问题描述】:

如何将图像设置为圆形。有没有更好的方法来设置带有圆圈框的图像? (尤其是 Windows 10 登录屏幕上的图像框)

Circle cir2 = new Circle(250,200,80); 
cir2.setStroke(Color.SEAGREEN); 
cir2.setFill(Color.SNOW); 
cir2.setEffect(new DropShadow(+25d, 0d, +2d, Color.DARKSEAGREEN));

【问题讨论】:

  • 更好的方法然后呢?发帖minimal reproducible example,然后提问。
  • 很抱歉,如果我没有提供有关我的问题的太多信息。我只有一个空白圆圈
  • 那是一个带有阴影的圆圈。不涉及图像。这也只有 4 行代码。目前尚不清楚您为什么要对此进行改进。

标签: javafx geometry


【解决方案1】:

ImagePattern 就是你要找的。​​p>

它用Image 填充Shape,因此您的代码可能如下所示

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();
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多