如何在圆圈中设置图像 [英] How to set an image in a circle

查看:264
本文介绍了如何在圆圈中设置图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在圆圈中设置图像。有没有更好的方法来设置带圆圈框架的图像? (特别是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));


解决方案



测试代码

  public void start(Stage primaryStage){
try {
BorderPane root = new BorderPane();
root.setPadding(new Insets(10));
场景场景=新场景(root,400,400);
标签l =新标签(我姐妹的形象);
l.setFont(Font.font(Font.getFontNames()。get(23),FontWeight.EXTRA_BOLD,14));
l.setAlignment(Pos.CENTER);
l.setPrefWidth(Double.MAX_VALUE);
root.setTop(l);
///////////////重要代码从这里开始
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));
//////////////重要代码在这里结束
root.setCenter(cir2);
primaryStage.setScene(scene);
primaryStage.show();
} catch(例外e){
e.printStackTrace();
}
}


How could I set an image in a circle. Is there a better way to set an image with a circled frame? (particularly the image frame on windows 10 login screen)

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

解决方案

ImagePattern is what you are looking for.

It fills a Shape with an Image, so your code might look like this

cir2.setFill(new ImagePattern(Image));

test code

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

这篇关于如何在圆圈中设置图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆