开发者

Java reading an image - java.lang.OutOfMemoryError

There is a 10MB Jpeg image i am trying to read using the following code, but i get a "Exception in thread "main" java.lang.OutOfMemoryError: Java heap space". I wonder if a 10MB image is too big to be read, should i 开发者_C百科increase the heap space if so.

Increasing the heap space should be the last alternative, so i wonder if there's any other way i could achieve this. My code is attached below;

BufferedImage image;
    try {

         image = ImageIO.read(new File("C:/Users/Administrator/Desktop/aa.jpg"));

            printDetails(image);

        } catch (IOException e) {

        }

Help appreciated.


Note that a 10MB JPEG can easily be decompressed to many more megabytes of uncompressed image data.

Assuming you're using a standard 24bit colorspace (8 bit for RGB each) and the image has dimensions of 10000 x 10000 pixels (which isn't too unrealistic, given the 10MB input size), then you'd need more than 286MB of storage to store the raw, uncompressed image data (and that's assuming that there is zero overhead).

That's significantly larger than the default maximum heap size of the Oracle client VM, so chances are that you'll need to increase the available heap memory using the -Xmx argument.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜