javafx 2.1在编辑Image后无法更新ImageView

时间:2012-05-31 10:54:42

标签: image imageview javafx-2

我创建了一个ImaveView并将Image对象影响到它。图像显示正确。 我还创建了一个按钮,打开一个新的舞台(里面显示图像)和一些幻灯片,以进行图像处理。 所以现在在进行一些编辑之后如何用新图像更新我的ImageView?

这就是我所做的:

//Boutton Traitement d'image
Button btnImageProcess = new Button("Traitement d'Image");
btnImageProcess.setOnAction(new EventHandler<ActionEvent>() {

    public void handle(ActionEvent event) {
        ImageProcess imageProcess = new ImageProcess();
        imageImageProcess = new Image(ImagePathImageProcess);
        imageViewImageProcess = ImageViewBuilder.create().image(imageImageProcess).build();
        ColorAdjust colorAdjust = ColorAdjustBuilder.create().build();
        imageViewImageProcess.setEffect(colorAdjust);
        // 
        Label saturationLabel = LabelBuilder.create().text("Saturation").build();
        GridPane.setConstraints(saturationLabel, 0, 0);
        Slider saturationSlider = SliderBuilder.create().value(50).build();
        colorAdjust.saturationProperty().bind(saturationSlider.valueProperty().divide(50).subtract(1));
        GridPane.setConstraints(saturationSlider, 1, 0);
        GridPane.setHgrow(saturationSlider, Priority.ALWAYS);
        Label saturationValueLabel = LabelBuilder.create().minWidth(75).maxWidth(75).build();
        saturationValueLabel.textProperty().bind(colorAdjust.saturationProperty().multiply(100).
                asString("%.2f%%"));
        GridPane.setConstraints(saturationValueLabel, 2, 0);
        // 
        Label hueLabel = LabelBuilder.create().text("Hue").build();
        GridPane.setConstraints(hueLabel, 0, 1);
        Slider hueSlider = SliderBuilder.create().value(50).build();
        colorAdjust.hueProperty().bind(hueSlider.valueProperty().divide(50).subtract(1));
        GridPane.setConstraints(hueSlider, 1, 1);
        GridPane.setHgrow(hueSlider, Priority.ALWAYS);
        Label hueValueLabel = LabelBuilder.create().minWidth(75).maxWidth(75).build();
        hueValueLabel.textProperty().bind(colorAdjust.hueProperty().multiply(100).asString("%.2f%%"));
        GridPane.setConstraints(hueValueLabel, 2, 1);
        // 
        Label brightnessLabel = LabelBuilder.create().text("Brightness").build();
        GridPane.setConstraints(brightnessLabel, 0, 2);
        Slider brightnessSlider = SliderBuilder.create().value(50).build();
        colorAdjust.brightnessProperty().bind(brightnessSlider.valueProperty().divide(50).subtract(1));
        GridPane.setConstraints(brightnessSlider, 1, 2);
        GridPane.setHgrow(brightnessSlider, Priority.ALWAYS);
        Label brightnessValueLabel = LabelBuilder.create().minWidth(75).maxWidth(75).build();
        brightnessValueLabel.textProperty().bind(colorAdjust.brightnessProperty().multiply(100).
                asString("%.2f%%"));
        GridPane.setConstraints(brightnessValueLabel, 2, 2);
        // 
        Label contrastLabel = LabelBuilder.create().text("Contrast").build();
        GridPane.setConstraints(contrastLabel, 0, 3);
        Slider contrastSlider = SliderBuilder.create().value(50).build();
        colorAdjust.contrastProperty().bind(contrastSlider.valueProperty().divide(50).subtract(1));
        GridPane.setConstraints(contrastSlider, 1, 3);
        GridPane.setHgrow(contrastSlider, Priority.ALWAYS);
        Label contrastValueLabel = LabelBuilder.create().minWidth(75).maxWidth(75).build();
        contrastValueLabel.textProperty().bind(colorAdjust.contrastProperty().multiply(100).asString("%.2f%%"));
        GridPane.setConstraints(contrastValueLabel, 2, 3);

        //Validate Button
        Button btnValider = new Button("Valider");
        btnValider.setOnAction(new EventHandler<ActionEvent>() {

            public void handle(ActionEvent event) {

                imageProcessStage.hide();
                ImageView imageView2 = new ImageView(imageViewImageProcess.getImage());
                imageView.setImage(imageViewImageProcess.getImage());

            }
        });

        GridPane.setConstraints(btnValider, 1, 4);
        GridPane.setHgrow(btnValider, Priority.ALWAYS);
        btnValider.setTranslateX(imageImageProcess.getWidth() / 12);
        btnValider.setTranslateY(7);

        //Validate Button
        Button btnReset = new Button("Reset");
        btnReset.setOnAction(new EventHandler<ActionEvent>() {

            public void handle(ActionEvent event) {
                ImageProcess ip = new ImageProcess();
                ip.setImagePath(ImagePathImageProcess);
                ip.start();
                imageProcessStage.close();
            }
        });
        GridPane.setConstraints(btnReset, 1, 4);
        GridPane.setHgrow(btnReset, Priority.ALWAYS);
        btnReset.setTranslateX(imageImageProcess.getWidth() / 12 + 82);
        btnReset.setTranslateY(7);

        //
        GridPane sliderGrid = GridPaneBuilder.create().children(saturationLabel, saturationSlider, saturationValueLabel,
                hueLabel, hueSlider, hueValueLabel,
                brightnessLabel, brightnessSlider, brightnessValueLabel,
                contrastLabel, contrastSlider, contrastValueLabel, btnValider, btnReset).build();

        imageViewImageProcess.setFitWidth(imageImageProcess.getWidth() / 3);
        imageViewImageProcess.setTranslateY(20);
        //imageView.setFitHeight(image.getHeight()/2);
        imageViewImageProcess.setPreserveRatio(true);
        imageViewImageProcess.setSmooth(true);
        imageViewImageProcess.setCache(true);

        rootImageProcess = BorderPaneBuilder.create().center(imageViewImageProcess).top(sliderGrid).
                build();

        imageProcessStage.setTitle("Traitement d'image");
        sceneImageProcess = new Scene(rootImageProcess);
        sceneImageProcess.getStylesheets().add(ImageProcess.class.getResource("ImageProcess.css").
                toExternalForm());
        imageProcessStage.setScene(sceneImageProcess);
        imageProcessStage.show();

    }
});

1 个答案:

答案 0 :(得分:0)

你有......

ImageView imageView2 = new ImageView(imageViewImageProcess.getImage());
imageView.setImage(imageViewImageProcess.getImage());

看起来不太有用