2001 JI Open Discussion Posted August 17, 2006 Posted August 17, 2006 By: swami - shakai2k Support for TIF Format 2002-11-10 18:51Hi All Is there anyway I can use TIF images for the Images, I am trying to use Tif images but unfortunately its not displaying. iText supports Tif Images by using the SUN API for Advanced Imaging(in short JAI). Please help me in this. Any help in getting this thing going will be greatly appreciated. Thanks Swami By: Teodor Danciu - teodord RE: Support for TIF Format 2002-11-11 13:29 Hi, I'm not familliar with this JAI API, but why I imagine it can load TIF files into java.awt.Image objects. If so, why is it that you cannot use this library to load images in JasperReports. You can make calls to this library in the report image expression itself, or you can pass the image as a java.awt.Image parameter to you report, in case you load it in the parent application. Note that you can use in report expression any class you might want to, as long as you reference it using its entire name (inlcluding the package) and you put it in the classpath when compiling and filling the report. I hope this helps. Teodor By: swami - shakai2k RE: Support for TIF Format 2002-11-12 09:29I tried doing using JAI the Tiff's that I have are compressed using LZW compression and the only way I can get around with this uncompress it using JAI, but the compression format must be passed into the iText Image so as to build it. Is there anyway I can set the type of compression for the Tiff Image. The other thing is an Image Expression takes only the following formats: java.lang.String java.net.URL java.io.InputStream java.awt.Image So I think if i can pass an java.lang.Object into the Image Expression and the compression format, I will be able get around this problem. Thanks swami By: Paulo Soares - psoares33 RE: Support for TIF Format 2002-11-12 10:02You can let JAI do all the work and pass to iText a java.awt.Image. See http://sourceforge.net/mailarchive/message.php?msg_id=2358954. By: swami - shakai2k RE: Support for TIF Format 2002-11-12 17:18Thank you all for your help. I had figured out how to use TIFFs in Jasper. The following is the explanation of how you can do it Use the SUN Java Advanced Imaging Library, you can get it from : http://java.sun.com/products/java-media/jai/downloads/download.html and this must help you convert the TIF image to an awt Image and which can be passed into Jasper Reports : ByteArraySeekableStream stream = new ByteArraySeekableStream(binaryData); ParameterBlock params = new ParameterBlock(); params.add(stream); // Specify to TIFF decoder to decode images as they are and // not to convert unsigned short images to byte images. TIFFDecodeParam decodeParam = new TIFFDecodeParam(); decodeParam.setDecodePaletteAsShorts(true); // Store the decode parameters in a RenderingHints to be sent // to the operation registry, and eventually to the TIFF decoder. RenderingHints hints = new RenderingHints(JAI.KEY_TILE_DECODING_PARAM,decodeParam); // Create an operator to decode the TIFF file. RenderedOp image1 = JAI.create("tiff", params, hints); // Find out the first image's data type. int dataType = image1.getSampleModel().getDataType(); RenderedOp image2 = null; if (dataType == DataBuffer.TYPE_BYTE) { // Display the byte image as it is. log.debug("TIFF image is type byte."); image2 = image1; } else if (dataType == DataBuffer.TYPE_USHORT) { // Convert the unsigned short image to byte image. log.debug("TIFF image is type ushort."); // Setup a standard window-level lookup table. */ byte[] tableData = new byte[0x10000]; for (int i = 0; i < 0x10000; i++) { tableData = (byte)(i >> 8); } // Create a LookupTableJAI object to be used with the // "lookup" operator. LookupTableJAI table = new LookupTableJAI(tableData); // Create an operator to lookup image1. image2 = JAI.create("lookup", image1, table); } else { log.debug("TIFF image is type " + dataType +", and will not be displayed."); } // Attach image2 to a scrolling panel to be displayed. BufferedImage bi = new BufferedImage(image2.getColorModel(),image2.copyData(), false, new Hashtable());
limbeek Posted September 9, 2011 Posted September 9, 2011 2001 JI Open DiscussionWrote: The following is the explanation of how you can do it Use the SUN Java Advanced Imaging Library, you can get it from : http://java.sun.com/products/java-media/jai/downloads/download.html and this must help you convert the TIF image to an awt Image and which can be passed into Jasper Reports : ByteArraySeekableStream stream = new ByteArraySeekableStream(binaryData); ParameterBlock params = new ParameterBlock(); params.add(stream); // Specify to TIFF decoder to decode images as they are and // not to convert unsigned short images to byte images. TIFFDecodeParam decodeParam = new TIFFDecodeParam(); decodeParam.setDecodePaletteAsShorts(true); // Store the decode parameters in a RenderingHints to be sent // to the operation registry, and eventually to the TIFF decoder. RenderingHints hints = new RenderingHints(JAI.KEY_TILE_DECODING_PARAM,decodeParam); // Create an operator to decode the TIFF file. RenderedOp image1 = JAI.create("tiff", params, hints); // Find out the first image's data type. int dataType = image1.getSampleModel().getDataType(); RenderedOp image2 = null; if (dataType == DataBuffer.TYPE_BYTE) { // Display the byte image as it is. log.debug("TIFF image is type byte."); image2 = image1; } else if (dataType == DataBuffer.TYPE_USHORT) { // Convert the unsigned short image to byte image. log.debug("TIFF image is type ushort."); // Setup a standard window-level lookup table. */ byte[] tableData = new byte[0x10000]; for (int i = 0; i < 0x10000; i++) { tableData = (byte)(i >> 8); } // Create a LookupTableJAI object to be used with the // "lookup" operator. LookupTableJAI table = new LookupTableJAI(tableData); // Create an operator to lookup image1. image2 = JAI.create("lookup", image1, table); } else { log.debug("TIFF image is type " + dataType +", and will not be displayed."); } // Attach image2 to a scrolling panel to be displayed. BufferedImage bi = new BufferedImage(image2.getColorModel(),image2.copyData(), false, new Hashtable()); Hi,What steps need to be followed to get it work. I'm so far that I have downloaded the SUN Java Advanced Imaging Library.Can you please help give me some clarity?Thanks,Gerard
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now