Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

BufferedImage & java.lang.OutOfMemoryError: Java heap space

807580May 12 2008 — edited Jun 8 2010
Hello,

I am using BufferedImage to read size of image (width and height).

This is happening in loop.

Method which is reading picture:
protected ImageInfo readImageInfo(File file){
  ImageInfo retVal = new ImageInfo();

  try {
    System.out.println(file.getAbsolutePath());
    BufferedImage img = ImageIO.read(file);
    int width = img.getWidth();
    int height = img.getHeight();

    if(width > retVal.getWidth()){
      height = (retVal.getWidth() * height)/width;
      retVal.setHeight(height);
    }else{
      retVal.setHeight(height);
      retVal.setWidth(width);
    }
  } catch (IOException e) {
    e.printStackTrace();
  }


   return retVal;
}
Number of picture can reach 100 000, and their approximate size is usually less than 1MB but it can be up to 5MB.

Why I am getting this exception and how to solve this?

Any help will be appreciated.

Thanks in advance!

passengerns
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 6 2010
Added on May 12 2008
12 comments
827 views