Text JavaFXImageView允许用户添加标记

Text JavaFXImageView允许用户添加标记,text,javafx,tags,imageview,Text,Javafx,Tags,Imageview,我正在使用javafx制作一个图像库,我希望有一个功能,允许用户在imageview中添加一些标记(用于人脸),当用户在imageview上单击时,它应该抓住鼠标指向的位置,并提示用户输入人脸名称并将其保存到数据库中 使用javafx可以实现这一点吗 如果是,我应该怎么做 谢谢你的帮助 下面是我的应用程序的示例输出: 当然有可能。我为一张图像创建了一个简单的示例,它在场景中添加了一个按钮,在单击图像的地方添加了一个圆圈。这应该证明这种方法 @Override public void start(

我正在使用javafx制作一个图像库,我希望有一个功能,允许用户在imageview中添加一些标记(用于人脸),当用户在imageview上单击时,它应该抓住鼠标指向的位置,并提示用户输入人脸名称并将其保存到数据库中

使用javafx可以实现这一点吗

如果是,我应该怎么做

谢谢你的帮助

下面是我的应用程序的示例输出:
当然有可能。我为一张
图像创建了一个简单的示例,它在场景中添加了一个按钮,在单击图像的地方添加了一个圆圈。这应该证明这种方法

@Override
public void start(Stage primaryStage) {
    ImageView imageView = new ImageView(...);
    imageView.setPreserveRatio(true);
    imageView.setFitHeight(200);
    StackPane pane = new StackPane();
    StackPane.setAlignment(imageView, Pos.TOP_LEFT);
    pane.getChildren().add(imageView);
    VBox box = new VBox(pane);

    pane.setOnMouseClicked(evt -> {
        if (evt.getButton() == MouseButton.PRIMARY) {
            // create node(s) that uses the click data
            Button button = new Button("Show point");
            button.setOnAction(e -> {
                // do something with the data on user interaction
                box.getChildren().remove(button);
                Circle circle = new Circle(evt.getX(), evt.getY(), 5, Color.RED);
                Pane circlePane = new Pane(circle);
                StackPane.setAlignment(circlePane, Pos.TOP_LEFT);
                pane.getChildren().add(circlePane);
            });
            box.getChildren().add(button);
        }
    });

    Scene scene = new Scene(box, 200, 300);

    primaryStage.setScene(scene);
    primaryStage.show();
}
对于您的申请,您将:

  • 创建不同的事件处理程序,根据需要创建和/或初始化UI,或显示对话框。您还可以直接将侦听器注册到
    ImageView
    (除非您需要像我一样在其上添加一些元素)
  • 使用
    evt.getX()*imageView.getImage().getWidth()/imageView.getLayoutBounds().getWidth()
    (绝对位置)或
    evt.getX()/imageView.getLayoutBounds().getWidth()
    (相对位置)计算图像坐标中的实际点击位置;对y位置进行相应的处理。直接在单击处理程序中执行此计算,而不是在用户提交输入的信息时执行,因为您可能希望用户能够调整图像的大小。此外,如果使用该属性,则需要相应地修改计算
  • 创建一个不同的线程,在用户提交编辑时将信息发送到数据库。当然,您还需要将有关当前显示在
    ImageView
    中的图像的一些信息存储在某处

您希望如何重新使用用户在对话框中输入的数据?谢谢@fabian,我正在使用event.getx()并设法在我想要的位置显示名称^^