We get the following exception
Exception in thread \"FileUploadManagerThread thread\" java.awt.color.CMMException: Invalid image format
at sun.awt.color.CMM.checkStatus(Unknown Source)
at sun.awt.color.ICC_Transform.<init>(Unknown Source)
at java.awt.image.ColorConvertOp.filter(Unknown Source)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.acceptPixels(Unknown Source)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.readImage(Native Method)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(Unknown Source)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(Unknown Source)
at javax.imageio.ImageReader.read(Unknown Source)
at wjhk.jupload2.filedata.helper.ImageReaderWriterHelper.readImage(ImageReaderWriterHelper.java:246)
at wjhk.jupload2.filedata.PictureFileData.createTranformedPictureFile(PictureFileData.java:595)
at wjhk.jupload2.filedata.PictureFileData.initTransformedPictureFile(PictureFileData.java:537)
at wjhk.jupload2.filedata.PictureFileData.beforeUpload(PictureFileData.java:228)
at wjhk.jupload2.upload.UploadFileData.beforeUpload(UploadFileData.java:277)
at wjhk.jupload2.upload.FileUploadManagerThread.prepareFiles(FileUploadManagerThread.java:1077)
at wjhk.jupload2.upload.FileUploadManagerThread.run(FileUploadManagerThread.java:332)
Our Customers use Photoshop and sometimes wired Color Profiles appear in some Jpeg Files (photographers that use a Canon EOS and the MAC Version of Photoshop CS3)
Some Sun JREs sometimes crash with this broken jpeg headers. I found a short java solution to fix it. See below
The trick is to read the jpeg as a stream and not with ImageIo.ImageReader.read ....
Short FIX
private static String getFormatName (Object o) {
try {
// Create an image input stream on the image
ImageInputStream iis = ImageIO.createImageInputStream (o);
// Find all image readers that recognize the image format Iterator iter = ImageIO.getImageReaders (iis); if (!iter.hasNext ()) // No readers found return null; // Use the first reader ImageReader reader = ( ImageReader ) iter.next (); // Close stream iis.close (); // Return the format name return reader.getFormatName (); } catch (IOException e) {} // The image could not be read return null;
}
USE:
String imageFormat = getFormatName (imageFile);
if (imageFormat.equalsIgnoreCase (\"JPEG\")) { FileInputStream input = new FileInputStream(imageFile); JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder (input); image = decoder.decodeAsBufferedImage (); input.close(); } else image = ImageIO.read (imageFile);
Look there i found this code: http://www.exampledepot.com/egs/javax.imageio/DiscType.html
Anonymous
Interesting !
Noted on my TODO list. I'll work on this one, when I finish my current task.
Etienne