Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Tiif toJpeg conversion  RSS feed

 
imran Faruqui
Greenhorn
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");
System.out.println("Done");
} catch (Exception e) {
e.printStackTrace();
System.exit(0);
}
}
}

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 :
http://in.f2.pg.briefcase.yahoo.com/biisimran/public/Ducky.tif
 
David O'Meara
Rancher
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!