1

I'm reading images from various URLs. And some of them became a very interesting problem.

The full error: javax.imageio.IIOException: Invalid icc profile: invalid number of icc markers

Some code, but I'm sure it won't help much:

            URLConnection wat = new URL(strurl).openConnection();
            wat.setRequestProperty("User-Agent", userAgent);
            InputStream in = null;
            try {
                in = wat.getInputStream();
            } catch(FileNotFoundException e) { 
                e.printStackTrace();
                Logger.getLogger().logException(e);
            }
            if(in == null) continue;
            ByteArrayOutputStream outArray = new ByteArrayOutputStream();

            byte[] bytes = new byte[50000];
            int bytesRead;
            while((bytesRead = in.read(bytes, 0, bytes.length)) > 0) {
                outArray.write(bytes, 0, bytesRead);
                bytesRead = 0;
            }
            in.close();
            String format = getFileFormat(outArray.toByteArray());
            in = new ByteArrayInputStream(outArray.toByteArray());
            BufferedImage image = null;
            try {
                image = ImageIO.read(in);
            } catch(IOException e) {
                e.printStackTrace();
                Logger.getLogger().logException(e);
            }

I read the bytes first to determine what file type is it.

This is the photo which seems to cause this exception to be thrown: http://www.loupiote.com/photos_l/3215396684-khmer-goddess-stone-statue-wat-phu-champasak-laos.jpg

Weirdly I couldn't find any information about this error.

EDIT: this is not actually a sollution, but because I was saving those files I stopped constructing a BufferedImage and just "dumped" those bytes to a file.

Tae-Sung Shin
  • 20,215
  • 33
  • 138
  • 240
Justas S
  • 584
  • 4
  • 12
  • 34
  • 1
    Similar question: http://stackoverflow.com/questions/4470958/why-does-loading-this-jpg-using-javaio-give-cmmexception – Luke Woodward Jun 15 '14 at 17:44
  • This actually is helpful... I believe that these standarts are the problem. But links to libraries used to convert it are dead. – Justas S Jun 16 '14 at 19:00

0 Answers0