• Post Reply Bookmark Topic Watch Topic
  • New Topic

Tiif toJpeg conversion

imran Faruqui
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.awt.image.RenderedImage;
import javax.media.jai.JAI;
import com.sun.media.jai.codec.FileSeekableStream;
import com.sun.media.jai.codec.ImageCodec;
import com.sun.media.jai.codec.ImageDecoder;

public class ConvTifJpg {
public static void main(String[] args) {
ConvTifJpg obj = new ConvTifJpg();
public ConvTifJpg(){
String sourcefilename = "C:\\Ducky.TIF";
String targetfilename = "C:\\Ducky.JPG";

try {
FileSeekableStream stream = null;
stream = new FileSeekableStream(sourcefilename);
ImageDecoder dec = ImageCodec.createImageDecoder("tiff", stream, null);
RenderedImage image = dec.decodeAsRenderedImage(0);
JAI.create("filestore",image ,targetfilename,"JPEG");
} catch (Exception e) {

When I am trieng to run above code I am getting following exception.....

java.lang.IllegalArgumentException: Bad endianness tag (not 0x4949 or 0x4d4d).
at com.sun.media.jai.codec.TIFFDirectory.getNumDirectories(TIFFDirectory.java:588)
at com.sun.media.jai.codecimpl.TIFFImageDecoder.getNumPages(TIFFImageDecoder.java:105)
at com.sun.media.jai.codecimpl.TIFFImageDecoder.decodeAsRenderedImage(TIFFImageDecoder.java:109)
at ConvTifJpg.<init>(ConvTifJpg.java:36)
at ConvTifJpg.main(ConvTifJpg.java:24)

......but if I save as any image to a TIFF image with the help of paint brush and pass this Image as source Image to above written code, it works fine and I get final converted JPEG image. So can any body help that whats wrong with the original TiFF image and give me perfect solution.

Original source Image is svaed at :
David O'Meara
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm.... not sure.
Moving to Java in General (intermediate) maybe?
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!