我試圖一次編輯五個圖像(一次使用javafx運動模糊),而不是一個接一個地選擇它們。這是我的代碼,我不完全確定我做錯了什麼,但是當我運行它時,只有文件夾中的最後一個圖像被編輯。其他人保持原樣。JavaFX批量編輯圖像
public class IterateThrough extends Application {
private Desktop desktop = Desktop.getDesktop();
@Override
public void start(Stage primaryStage) throws IOException {
File dir = new File("filepath");
File [] directoryListing = dir.listFiles();
if (directoryListing != null) {
for (File file : directoryListing) {
if(file.getName().toLowerCase().endsWith(".jpeg")){
//desktop.open(file);
Image image = new Image(new FileInputStream(file));
//Setting the image view
ImageView imageView = new ImageView(image);
//setting the fit height and width of the image view
imageView.setFitHeight(600);
imageView.setFitWidth(500);
//Setting the preserve ratio of the image view
imageView.setPreserveRatio(true);
// instantiate Motion Blur class
MotionBlur motionBlur = new MotionBlur();
// set blur radius and blur angle
motionBlur.setRadius(15.0);
motionBlur.setAngle(110.0);
//set imageView effect
imageView.setEffect(motionBlur);
//Creating a Group object
Group root = new Group(imageView);
//Creating a scene object
Scene scene = new Scene(root, 600, 500);
//Setting title to the Stage
primaryStage.setTitle("Loading an image");
//Adding scene to the stage
primaryStage.setScene(scene);
//Displaying the contents of the stage
primaryStage.show();
}
}
}
}
public static void main(String[] args) {
launch(args);
}
}
我假設你正在使用的單詞「編輯」是指「顯示,」但我還是不明白你想要做什麼。你想顯示所有的圖像是在同一時間,在彼此之上?您是否試圖一次顯示它們,而將模糊用作過渡效果? – VGR
@VGR我試圖一次一個地顯示它們,同時使用模糊作爲過渡效果。 – diamondgirl
然後,您可能會想要使用[時間軸](http://docs.oracle.com/javase/8/javafx/api/javafx/animation/Timeline.html)。但首先,您需要更好地定義您希望過渡的樣子。僅僅模糊圖像並不構成過渡效果。你想讓一張圖像越來越模糊,然後被下一張圖像的模糊版本所取代,而這種模糊版本逐漸變得不明朗? – VGR