6

After obtaining an image from db, when i try to resize it, by passing width using the below code

        public static BufferedImage resize(final byte[] pImageData,
                    final int width, final int height, final int maxLength, final int minLength, final String imageSubType) throws Exception {

                InputStream is = null;
                BufferedImage resizeImageJpg = null;
                try {

                    is = new ByteArrayInputStream(pImageData);
                    BufferedImage originalImage = ImageIO.read(is);
                     --------------------

    }
   }

The following exception is thrown at line:

                    BufferedImage originalImage = ImageIO.read(is);

Exception:

Caused by: java.awt.color.CMMException: Invalid image format
    at sun.awt.color.CMM.checkStatus(CMM.java:131)
    at sun.awt.color.ICC_Transform.<init>(ICC_Transform.java:89)
    at java.awt.image.ColorConvertOp.filter(ColorConvertOp.java:516)
    at com.sun.imageio.plugins.jpeg.JPEGImageReader.acceptPixels(JPEGImageReader.java:1169)
    at com.sun.imageio.plugins.jpeg.JPEGImageReader.readImage(Native Method)
    at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:1137)
    at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:948)
    at javax.imageio.ImageIO.read(ImageIO.java:1422)
    at javax.imageio.ImageIO.read(ImageIO.java:1326)

Any ideas on why this error is thrown only for certain images. Is there anything wrong with the image. If so, what can be the possible errors

Npa
  • 617
  • 2
  • 15
  • 26
  • 1
    possible duplicate of [Is there a 100% Java alternative to ImageIO for reading JPEG files?](http://stackoverflow.com/questions/2999528/is-there-a-100-java-alternative-to-imageio-for-reading-jpeg-files) – Hakan Serce Dec 16 '12 at 22:13
  • 2
    possible duplicate of [why does loading this jpg give cmmexception](http://stackoverflow.com/questions/4470958/why-does-loading-this-jpg-using-javaio-give-cmmexception) – Jool May 16 '13 at 16:09

1 Answers1

2

BTW, this CMMException problem is fixed in JDK8 (notice the commit at the bottom of http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7064516). I've confirmed that a pre-release build of JDK8 properly loads images that JDK7 fails on as described above.

cemerick
  • 5,916
  • 5
  • 30
  • 51
  • We are seeing this error on our Confluence 3.4.7 server. Is there any chance that this version of Confluence will work with JDK 8? – PAUL MENA Sep 28 '22 at 18:08