donchen Posted November 10, 2009 Share Posted November 10, 2009 Hi guys, Can i know if its possible to convert TIFs images to GIFs images? I did some research on JAVA's imageIO but I think it doesn't support TIF and I need some sort of plugins. Anyone can point me to some sample code? Thanks! Link to comment Share on other sites More sharing options...
0 kjordan2001 Posted November 10, 2009 Share Posted November 10, 2009 Hi guys,Can i know if its possible to convert TIFs images to GIFs images? I did some research on JAVA's imageIO but I think it doesn't support TIF and I need some sort of plugins. Anyone can point me to some sample code? Thanks! You might look at this library if it's not too much overkill for your project. It supports importing TIFF files. Link to comment Share on other sites More sharing options...
0 donchen Posted November 10, 2009 Author Share Posted November 10, 2009 Haha, thanks jordan. Coincidentally, i was browsing that exact same page as well! Lol. I am reading more into it right now. Do you know of site that have sample codes using JAI ? Thanks! Link to comment Share on other sites More sharing options...
0 donchen Posted November 10, 2009 Author Share Posted November 10, 2009 import java.io.FileOutputStream;import javax.media.jai.JAI; import javax.media.jai.RenderedOp; public class TIFFImageConverter { public static void main(String [] args) { // Define the source and destination file names. String inputFile = "images/test.tif"; String outputFile = "images/test.gif"; // Load the input image. RenderedOp image = JAI.create("fileload", inputFile); try { // Encode the file as a JPEG image. FileOutputStream stream =new FileOutputStream(outputFile); JAI.create("encode", image, stream, "GIF" ,null); // Store the image in the BMP format. JAI.create("filestore", image, outputFile, "GIF", null); } catch(Exception e) { e.printStackTrace(); } } } The above code spits the following error. java.lang.IllegalArgumentException: Encode No ImageEncoder is available for this format or this image cannot be encoded with the given encoding parameters. at javax.media.jai.JAI.createNS(JAI.java:1087) at javax.media.jai.JAI.create(JAI.java:973) at javax.media.jai.JAI.create(JAI.java:1668) at TIFFImageConverter.main(TIFFImageConverter.java:23) The exception is thrown at this line. -> JAI.create("encode", image, stream, "GIF" ,null); But i thought it supported GIF files? Regards Don Oh shucks, reading deeper into it. I think JAI only DECODES GIFs but not ENCODE them... am i right? Link to comment Share on other sites More sharing options...
0 kjordan2001 Posted November 11, 2009 Share Posted November 11, 2009 Looks that way. You might try using ImageIO to write out the RenderedOp image since RenderedOp seems to implement RenderedImage which ImageIO's write will take. Link to comment Share on other sites More sharing options...
0 donchen Posted November 13, 2009 Author Share Posted November 13, 2009 Thanks jordan, i managed to solve it already! Cheers! Link to comment Share on other sites More sharing options...
Question
donchen
Hi guys,
Can i know if its possible to convert TIFs images to GIFs images? I did some research on JAVA's imageIO but I think it doesn't support TIF and I need some sort of plugins.
Anyone can point me to some sample code?
Thanks!
Link to comment
Share on other sites
5 answers to this question
Recommended Posts