我创建了一个 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();
}
});