sweet idleness

Where is your heart at?

January 15, 2008

Lyrics by Rufus Wainwright and performed by Jaime Cullum

This song appears on Meet the Robinsons OST. 

04. Jamie Cullum - Where Is Your Heart At (Jamie Cullum)

(more…)

Posted by george at 2:18 pm | permalink | View this entry

Read and Write JPEG Exif Using the javax.imageio.metadata package.

September 6, 2007

The javax.imageio.metadata package contains classes and interfaces for accessing metadata. Here’s a snippet of code that illustrates how the image metadata is preserved.

 

 // Set the input stream.reader.setInput(new FileImageInputStream(new File(inputFileName)));

// Get the image metadata.
IIOMetadata imageMetadata = reader.getImageMetadata(0);

// Read the image.
RenderedImage image = reader.read(0);

// Set the output stream.
writer.setOutput(new FileImageOutputStream(new         File(outputFileName)));

// Write the image.
writer.write(null, new IIOImage(image, null, imageMetadata),  writeParam);

Code posted by Brian Burkhalteon a Java Advanced Imaging Discussion Forum. 

After a few minutes of running the code on your stock of images, you’ll get to meet these errors:

Exception in thread “main” javax.imageio.IIOException: Missing Huffman code table entry
        at com.sun.imageio.plugins.jpeg.JPEGImageWriter.writeImage(Native Method)
        at com.sun.imageio.plugins.jpeg.JPEGImageWriter.write(JPEGImageWriter.java:971)
        at JPEGIOMetadataExample.main(JPEGIOMetadataExample.java:160) 

Exception in thread “main” javax.imageio.IIOException: JFIF APP0 must be first marker after SOI
        at com.sun.imageio.plugins.jpeg.JPEGMetadata.<init>(JPEGMetadata.java:206)
        at com.sun.imageio.plugins.jpeg.JPEGImageReader.getImageMetadata(JPEGImageReader.java:853)
        at JPEGIOMetadataExample.main(JPEGIOMetadataExample.java:151)

Exception in thread “main” javax.imageio.IIOException: ICC APP2 encountered without prior JFIF!
        at com.sun.imageio.plugins.jpeg.JPEGMetadata.<init>(JPEGMetadata.java:263)
        at com.sun.imageio.plugins.jpeg.JPEGImageReader.getImageMetadata(JPEGImageReader.java:853)
        at JPEGIOMetadataExample.main(JPEGIOMetadataExample.java:151)
 

The Missing Huffman code table entry error can be fixed by passing a parameter of class JPEGImageWriteParam and calling setOptimizeHuffmanTables(true) when writing it to disk.

 

JPEGImageWriteParam param = new JPEGImageWriteParam(Locale.getDefault());
param.setCompressionQuality(quality);
param.setOptimizeHuffmanTables(true);

Regarding the other 2, I got this from one of the forums:  

You must be using the Java SE JPEG reader which has this known problem…

… 

The JAI Image I/O Tools JPEG reader does not have this problem as far as we
know so you might try that:

https://jai-imageio.dev.java.net

Brian

Posted by george at 9:04 pm | permalink | comments[22]

Sponsored Links

About Me

My name is George and this is my blog.

No. Not really.

 

Subscribe

Technorati
Bloglines