• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

Ruchika Verma
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.write(image); // (*)
public static void main(String args[])throws IOException{


Please Help!!!
Ulf Dittmer
Posts: 42972
  • 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?
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!