简体   繁体   English

图像占用大量内存

[英]High memory consumption by an Image

Below is a sample code. 以下是示例代码。 Where it loads 6 Images and displays them in a screen. 它在其中加载6张图像并在屏幕上显示它们。 Each Image size is of 2.3 MB. 每个图像大小为2.3 MB。 So on loading each Image, I should see a rise of memory consumption of 3 MB approx for each Image loaded. 因此,在加载每个映像时,我应该看到每个加载的映像的内存消耗大约增加了3 MB。 But it turns out that it loads 10 MB for each Image. 但是事实证明,每个图像加载10 MB。

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. 在我的应用程序中,事实证明,一个1.3MB的图像占用50 MB的空间。 Any reasons? 有什么原因吗?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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