• 0

[JAVA] Converting TIFs images to GIFs


Question

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

  • 0
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

  • 0

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

  • 0
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

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.