3 つの画像をサムネイルとして表示する単純な JavaFx(2.0) アプリケーションを実行しようとしています。OS は Windows7 で、NetBeans 7.2 を使用しています コードはこれです-
public class FX17 extends Application{
public static void main(String[] args){
launch(args);
}
public void start(Stage stage){
HBox photoBar = new HBox();
Group root = new Group();
File f1 = new File("C:\\Users\\Pictures\\IMG_0021.jpg");
File f2 = new File("C:\\Users\\Pictures\\IMG_0022.jpg");
File f3 = new File("C:\\Users\\Pictures\\IMG_0023.jpg");
Image i1 = new Image(f1.toURI().toString());
Image i2 = new Image(f2.toURI().toString());
Image i3 = new Image(f3.toURI().toString());
ImageView iv1 = new ImageView(i1);
//iv1.setImage(i1);
iv1.setFitWidth(50);
iv1.setPreserveRatio(true);
iv1.setCache(true);
ImageView iv2 = new ImageView(i2);
//iv2.setImage(i2);
iv2.setFitWidth(50);
iv2.setPreserveRatio(true);
iv2.setCache(true);
ImageView iv3 = new ImageView(i3);
// iv3.setImage(i3);
iv3.setFitWidth(50);
iv3.setPreserveRatio(true);
iv3.setCache(true);
photoBar.getChildren().add(iv1);
photoBar.getChildren().add(iv2);
photoBar.getChildren().add(iv3);
//C:\Users\Public\Pictures\Sample Pictures
BorderPane pane = new BorderPane();
pane.setTop(photoBar);
root.getChildren().add(photoBar);
//pane.setLeft(linkBar);
Scene scene = new Scene(root);
scene.setFill(Color.BLACK);
stage.setScene(scene);
stage.setWidth(415);
stage.setHeight(200);
stage.sizeToScene();
stage.show();
}
}
2 つの画像の場合、プログラムが実行され、2 つのサムネイルが表示されますが、3 つ以上の画像の場合、プログラムは OutOfMemoryError をスローします。画像はjpgで、平均サイズは2.5MBです。確認する必要がある設定や画像形式はありますか? 次のコンストラクターは私にとってはうまくいきます。Image img = new Image(file.toURI().toString(),100,100,false,false);アスペクト比,smooth は false です。