2017-06-20 10 views
0

私はフォルダ内にある(javafxモーションブラーを使用して)フォルダ内にある5つの画像を順に選択するのではなく、編集しようとしています。これは私のコードです、私は間違って何をしているのか正確にはわかりませんが、私がそれを実行すると、フォルダ内の最後の画像だけが編集されます。他のものはそのままです。JavaFX一括編集画像

ときprimaryStage最初のショー()、その命令のFXスレッドの一時停止、残りの画像はなりませんので、
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); 
} 

} 
+0

I「には、ディスプレイを」あなたが意味する単語「編集」を使用していると仮定しますが、私はまだあなたが何をしようとして理解していません。あなたは、すべての画像を同時に表示したいですか?トランジションエフェクトとしてぼかしを使用しながら、それらを1つずつ表示しようとしていますか? – VGR

+0

@VGR私はトランジションエフェクトとしてぼかしを使っている間、一度に1つずつ表示しようとしています。 – diamondgirl

+1

[タイムライン](http://docs.oracle.com/javase/8/javafx/api/javafx/animation/Timeline.html)を使用することをお勧めします。しかし、まず、遷移をどのように見せたいかを明確に定義する必要があります。単に画像をぼかしても、トランジション効果はありません。 1つの画像を次第にぼかすようにした後、次の画像のぼかしたバージョンに置き換えて徐々に消えるようにしましたか? – VGR

答えて

0

まず、あなただけのために、各ループで)(primaryStageショーをさせてはなりませんウィンドウを閉じると、ループは残りのために続行されず、アプリケーションの終了を表します。

だから、すべての画像が読み込まれた後に、各ループの外側にprimaryStage show()を置く方が良いです。

2番目に、すべての画像を格納するために「グループ」コンテナを使用しないでください.VBox/HBox/FlowPaneを使用することをおすすめします。

ここに参考用に変更されたコードです。

public class IterateThrough2 extends Application{ 
    private Desktop desktop = Desktop.getDesktop(); 
    @Override 
    public void start(Stage primaryStage) throws IOException{ 
    File dir = new File("filepath"); 
    File[] directoryListing = dir.listFiles(); 

    FlowPane root = new FlowPane(); 

    if(directoryListing != null){ 
     for(File file : directoryListing){ 
     if(file.getName().toLowerCase().endsWith(".jpeg")){ 
      Image image = new Image(new FileInputStream(file)); 
      ImageView imageView = new ImageView(image); 
      imageView.setFitHeight(600); 
      imageView.setFitWidth(500); 
      imageView.setPreserveRatio(true); 
      MotionBlur motionBlur = new MotionBlur(); 
      motionBlur.setRadius(15.0); 
      motionBlur.setAngle(110.0); 
      imageView.setEffect(motionBlur); 
      root.getChildren().add(imageView); 
     } 
     } 
    } 

    Scene scene = new Scene(root, 600, 500); 
    primaryStage.setTitle("Loading an image"); 
    primaryStage.setScene(scene); 
    primaryStage.show(); 
    } 

    public static void main(String[] args){ 
    launch(args); 
    } 
} 

enter image description here

+0

最初の画像のみを編集して表示しています。 – diamondgirl

+0

@diamondgirl あなたはあなたのウィンドウを拡大する必要があります、私のアップロードされた画像を参照してください。 – yab

+0

ありがとうございます! – diamondgirl