简体   繁体   中英

High memory consumption by an Image

Below is a sample code. Where it loads 6 Images and displays them in a screen. Each Image size is of 2.3 MB. So on loading each Image, I should see a rise of memory consumption of 3 MB approx for each Image loaded. But it turns out that it loads 10 MB for each Image.

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import javafx.application.Application;
import javafx.geometry.Orientation;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.ScrollBar;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class Test extends Application {

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

@Override
public void start(Stage primaryStage) throws Exception {
ScrollBar bar = new ScrollBar();
bar.setOrientation(Orientation.VERTICAL);


final VBox box = new VBox();
Group root = new Group();
root.getChildren().addAll(box, bar);
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.setTitle("Layout Sample");
primaryStage.show();


for (int ik = 0; ik < 6; ik++) {
    System.out.println("1");
    ImageView i = new ImageView();
    InputStream is = new FileInputStream(new File("C:\\Users\\Jatin\\Documents\\BarcodeNew\\w.png"));
    Image im = new Image(is);
    i.setImage(im);
    box.getChildren().add(i);
    is.close();
}

//r.close();


}
}

In my application it is turning out that, a 1.3MB Image is taking 50 MB space. Any reasons?

请记住,PNG图像的文件大小和内存中未压缩图像的内存消耗是非常不同的。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM