javax.imageio.IIOException: Missing Huffman code

N

niko

Posted this in the sun java forums without any replies. Posting it
here too...
---------------------------------------------------------------------------


Does anyone know what the exception "javax.imageio.IIOException:
Missing Huffman code table entry" is indicating? My code reads and
writes an image to disk using the image io APIs. Most images are ok
but for some of them, I get the exception. The images come from
external sources, usually direct from digital cameras and look fine in
any browser/viewer.

Any ideas?

This is the code:

static public void testProblem(File src, File dest, IPTCInfo info)
throws Exception {

ImageReader reader = null;
ImageWriter writer = null;
ImageInputStream iis = null;
ImageOutputStream ios = null;
BufferedImage buff = null;
IIOMetadata metadata = null;


try {
// First, find a reader for jpg which handles metdata

Iterator it = ImageIO.getImageReadersByFormatName("jpg");
while (it.hasNext() && metadata==null) {

/**
* Try this reader...
*/

reader = (ImageReader) it.next();

//Open up the ImageInputStream

iis = ImageIO.createImageInputStream(src);

if (iis!=null) {

// Set the readers stream
reader.setInput(iis);
// Read the pixels and metadata
buff = reader.read(0);

metadata = reader.getImageMetadata(0);

if (metadata==null)
iis.close();

}
}

if (metadata==null)
throw new Exception("IPTCUtil: No metadata found");


// Writing the File

writer = ImageIO.getImageWriter(reader);

IIOImage outImage = new IIOImage(buff,null, metadata);
ios = ImageIO.createImageOutputStream(dest);
writer.setOutput(ios);
writer.write(metadata,outImage,null);

} catch (Exception ex) {
throw ex;
} finally {
if (reader!=null)
reader.dispose();
if (writer!=null)
writer.dispose();
if (iis!=null)
iis.close();
if (ios!=null)
ios.close();
}
}
 
A

Andrey Kuznetsov

Does anyone know what the exception "javax.imageio.IIOException:
Missing Huffman code table entry" is indicating?

Huffman table should be embedded into image.
Without Huffman table image can't be decompressed.
 
N

niko

Andrey Kuznetsov said:
Huffman table should be embedded into image.
Without Huffman table image can't be decompressed.

Thanx, I was able to store the file by passing a parameter of class
JPEGImageWriteParam and calling setOptimizeHuffmanTables(true)
when writing it to disk.



/ niko
 
N

niko

Andrey Kuznetsov said:
Huffman table should be embedded into image.
Without Huffman table image can't be decompressed.

Also, the images that gave the exception look fine when I view them.
But, do you think that they might be faulty or anything? (By faulty I
mean non JPEG conformant, but still viewable by "not so picky"
viewers?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top