Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Wednesday, January 09, 2008

Changing the colour model of a BufferedImage in Coldfusion 8

We carry out a lot of image processing to achieve our photos to art solution and our frame and canvas preview feature. Most of this code was written before Coldfusion 8, which introduced lots of new image processing features native to the language. As a result, we have written Java code, some in-line with our Coldfusion, some in external Java classes. When trialling our upgrade to Coldfusion 8, we were pleased to find that our existing Java image code worked just as it did previously on Coldfusion 7. However, a week ago, we discovered that that some users were receiving timeout errors when uploading JPEGs to our photos to art solution. It turned out that the error only occurred with certain types of JPEGs, those which Java's BufferedImage class considers to have a custom colour model. We have code which converts these to workable RGB images, but it was this code which was failing on Coldfusion 8. I put the code in its simplest form, into Java...

BufferedImage bi_out = new BufferedImage(bi_in.getWidth(),
     bi_in.getHeight(), BufferedImage.TYPE_3BYTE_BGR);
Graphics2D g = bi_out.createGraphics();
g.drawImage(bi_in, 0, 0, null);
g.dispose();
...and ran some tests outside of Coldfusion, through both the JRE 1.6.0, and the one in my standard Coldfusion 8 install. Both JREs worked without problems, which meant the problem must lie with Coldfusion, which led me to this solution. So if you are having problems using Java to convert a BufferedImage of TYPE_CUSTOM in Coldfusion 8, you could try one of the two fixes below, as outlined here:
  1. Remove clibwrapper_jiio.jar from "lib" folder.
  2. Or, set this system property to the JVM. -Dcom.sun.media.imageio.disableCodecLib=true . You can set this in [cf-install_dir]/runtime/bin/jvm.config if you are using standalone coldfusion server.
So far I have been unable to find any negative side-effects of this fix.

 
Copyright Magnolia Box