我想運行簡單的JavaFx(2.0)應用程序,它將以縮略圖顯示三個圖像。 OS是Windows7中,我使用NetBeans 7.2 代碼是這個 -Javafx outofmemory錯誤
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();
}
}
對於兩個圖像的程序運行和顯示兩個縮略圖,但3倍或更多的圖像,程序引發的OutOfMemoryError。圖像是JPG格式,平均大小爲2.5MB。有一些設置或圖像格式需要檢查嗎? 以下構造函數適合我。 Image img = new Image(file.toURI()。toString(),100,100,false,false);寬高比,平滑爲false。
大家好,下面的構造函數工作正常 - – Chirota