Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Exception while reading tiff file(Coverting tif to JPEG)  RSS feed

 
Ruchika Verma
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have installed JAI Image I/O 1.1 but when I run this prog I get an exception- Exception in thread "main" java.lang.IllegalStateException: Input not set!
at com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.getNumImages(TIFFImageReader.java:234)

My code is:
import javax.imageio.stream.*;
import javax.imageio.*;
import javax.swing.*;
import com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader;

import java.awt.*;
import java.awt.image.*;
import java.io.*;

class convertToJpg{

public static void convert2Jpg(String path) throws IOException {
ImageReader reader = ImageIO.getImageReadersByFormatName("tiff").next();
ImageInputStream iis = ImageIO.createImageInputStream(new File(path));
reader.setInput(iis, false);
ImageWriter writer = ImageIO.getImageWritersByFormatName("jpg").next();
String filename = path.substring(path.lastIndexOf("\\")+1, path.lastIndexOf("."));
for (int i=0; i<reader.getNumImages(true); i++) {
BufferedImage image = reader.read(i);
String outputFileName = filename+"_"+(i+1)+".jpg";
ImageOutputStream ios = ImageIO.createImageOutputStream(new File(outputFileName));
writer.setOutput(ios);
writer.write(image); // (*)
}
}
public static void main(String args[])throws IOException{

convert2Jpg("/src/CCITT_1.tif");

}
Please Help!!!
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you really have a top-level directory called "src" in your file system in which the image resides?

Which statement throws the exception?
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!