2

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));
fabian
  • 80,457
  • 12
  • 86
  • 114
ben
  • 325
  • 1
  • 5
  • 15
  • 1
    A better way then what? Post [mcve] and then ask question. – MBec Feb 08 '17 at 14:54
  • I am sorry if I didn't provide much info about my problem. all I've got is a blank circle – ben Feb 08 '17 at 15:08
  • 2
    Possible duplicate of [Put a image in a circle view](http://stackoverflow.com/questions/20708295/put-a-image-in-a-circle-view) – Hypnic Jerk Feb 08 '17 at 15:54
  • That is a circle with a drop shadow. There is no image involved. Also that's only 4 lines of code. It's unclear why you'd want to improve on this. – fabian Feb 08 '17 at 16:52

1 Answers1

15

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

enter image description here

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();
    }
}
Elltz
  • 10,730
  • 4
  • 31
  • 59