This discussion is archived
3 Replies Latest reply: Feb 11, 2013 12:44 AM by 990282 RSS

How to read large images in Java ??

990282 Newbie
Currently Being Moderated
Hello All

I am reading an Jpeg file using following snippets

view plaincopy to clipboardprint?
Note: Text content in the code blocks is automatically word-wrapped

BufferedImage img = ImageIO.read(f);



the file i try to read is 6480 and 4320 in dimension and just 2.34 MB in size. my heap size is 1024 MB.and i want to read file even larger in size say 25 - 30 mb and 10,000 * 12,000 in dimensions. then what all experts suggest me to accomplish my goal

getting following exception


view plaincopy to clipboardprint?
Note: Text content in the code blocks is automatically word-wrapped

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
at java.awt.image.DataBufferByte.<init>(DataBufferByte.java:58)
at java.awt.image.ComponentSampleModel.createDataBuffer(ComponentSampleModel.java:397)
at java.awt.image.Raster.createWritableRaster(Raster.java:938)
at javax.imageio.ImageTypeSpecifier.createBufferedImage(ImageTypeSpecifier.java:1056)
at javax.imageio.ImageReader.getDestination(ImageReader.java:2879)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:943)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:915)
at javax.imageio.ImageIO.read(ImageIO.java:1422)
at javax.imageio.ImageIO.read(ImageIO.java:1282)
at com.mmg.app.gui.ImageGalleryContainer$1.actionPerformed(ImageGalleryContainer.java:104)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6216)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
at java.awt.Component.processEvent(Component.java:5981)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4583)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4413)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4556)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4220)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4150)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4413)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
  • 1. Re: How to read large images in Java ??
    Kayaman Guru
    Currently Being Moderated
    Give the app a couple of gigs of heap, try again.
  • 2. Re: How to read large images in Java ??
    gimbal2 Guru
    Currently Being Moderated
    Keep in mind that the size you see on disc is the compressed size. The image living in memory after loading it is decompressed and will use quite a bit more memory. That amount is likely duplicated once or twice when working with said image, depending on what you do with it.
  • 3. Re: How to read large images in Java ??
    990282 Newbie
    Currently Being Moderated
    Hello

    when i run my code out of ide it works fine.

    my myeclipse.ini is

    -startup
    ../Common/plugins/org.eclipse.equinox.launcher_1.0.201.R35x_v20090715.jar
    --launcher.library
    ../Common/plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.0.200.v20090519
    -install
    C:/Program Files/Genuitec/MyEclipse-8.6
    -vm
    C:/Program Files/Genuitec/Common/binary/com.sun.java.jdk.win32.x86_1.6.0.013/jre/bin/client/jvm.dll
    -configuration
    configuration
    -vmargs
    -Xmx1024m
    -XX:MaxPermSize=256m
    -XX:ReservedCodeCacheSize=128m


    so why can i run same code with no error outside of IDE ?

    Thank You
    Mihir Parekh

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points