1

I am working on an image compression technique, I have compressed the image into .jpg format and stored it, using Java, I used various functions in java like:

obj.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
obj.setCompressionQuality(0.05f);

but it only works if the image size is < 6mb, if it goes beyond that, it throws an exception,

I want to know about some tools(libraries) that are available for image processing.

Thanks.

The Stack trace is given below, its lack of heap memory, this Thread

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
        at java.awt.image.DataBufferByte.<init>(DataBufferByte.java:58)
        at java.awt.image.ComponentSampleModel.createDataBuffer(ComponentSampleM
odel.java:397)
        at java.awt.image.Raster.createWritableRaster(Raster.java:938)
        at javax.imageio.ImageTypeSpecifier.createBufferedImage(ImageTypeSpecifi
er.java:1169)
        at javax.imageio.ImageReader.getDestination(ImageReader.java:2879)
        at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageRe
ader.java:943)
        at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.jav
a:915)
        at javax.imageio.ImageIO.read(ImageIO.java:1422)
        at javax.imageio.ImageIO.read(ImageIO.java:1282)
        at Compresssion.main(Compresssion.java:13)
Community
  • 1
  • 1
Alexander Zaldostanov
  • 2,907
  • 4
  • 30
  • 39
  • Could you provide a stack trace of the thrown exception? – Tresdon Aug 07 '15 at 06:50
  • 1
    Try looking at ComponentSampleModel.createDataBuffer during the debug and see how many bytes it wants to create. Maybe it's simply too large for the memory. – Enerccio Aug 07 '15 at 07:14
  • I'll look into that, thanks man – Alexander Zaldostanov Aug 07 '15 at 07:18
  • 1
    The java option -Xmx=512m to increase memory is known? – Joop Eggen Aug 07 '15 at 07:47
  • I tried that, it didn't work, no heap space available :( – Alexander Zaldostanov Aug 07 '15 at 07:48
  • What is the maximum heap size you are willing to allocate to the JVM? – ctrueden Aug 07 '15 at 21:36
  • @AlexanderZaldostanov What is your current heap size (when you get the exception)? And what is the amount of memory available for the heap? A normal (RGB/YCbCr encoded) JPEG image will need at least `width` x `height` x `3` bytes of *continuous* free memory. If you don't have this much memory available, it will be very hard to do anything with the image in Java. Also, when you talk about *image size*, do you mean encoded *file size* or actual decoded *image memory size*? – Harald K Aug 14 '15 at 12:08
  • haraldK I fixed the error bud, Thanks for asking , it was RGB and I compress it to kb's, like 45MB file to KB's, Image format is jpeg – Alexander Zaldostanov Aug 14 '15 at 18:41

0 Answers0