0

i am not able to add jai libraries in jdk. i have already set everythig on correct position. I need to read tiff image. But that is not working so i tried for converting tiff file into JPEG. but still getting same error. classpath set. Everything is fine. Code is compiling fine. i found on stackflow:

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.awt.image.RenderedImage;
import com.sun.media.jai.codecimpl.JPEGCodec;
import com.sun.media.jai.codecimpl.*;
import com.sun.media.jai.codecimpl.JPEGImageEncoder;
import com.sun.media.jai.codec.SeekableStream;
import com.sun.media.jai.codec.FileSeekableStream;
import com.sun.media.jai.codec.TIFFDecodeParam;
import com.sun.media.jai.codec.ImageDecoder;
import com.sun.media.jai.codec.ImageCodec;
import com.sun.media.jai.codec.*;

public class TiffUtils {  
public static void TiffToJpg(String tiff, String output)throws IOException{ 
    File tiffFile = new File(tiff);   
    SeekableStream s = new FileSeekableStream(tiffFile);   
    TIFFDecodeParam param = null; 
    ImageDecoder dec = ImageCodec.createImageDecoder("tiff", s, param);   
    RenderedImage op = dec.decodeAsRenderedImage(0);
    FileOutputStream fos = new FileOutputStream(output);

    JPEGEncodeParam jpgparam = new JPEGEncodeParam();
    jpgparam.setQuality(67);
    ImageEncoder en = ImageCodec.createImageEncoder("jpeg", fos, jpgparam);
    en.encode(op);
    fos.flush();
     fos.close();}   
  public static void main(String[] args) throws Exception {    
  TiffUtils.TiffToJpg("C:\\Users\\JavaPrg\\Input\\def.tif","C:\\Users\\JavaPrg\\Input\\test.jpg");   
  }
 }

ar run time i am getting NoClassDefFound error for seekeableStream. So now i dont want use JAI and JAIImageIO Apis

user23385
  • 111
  • 2
  • 12
  • Sounds to me like you have a class path issue, if the code compiles but you get `NoClassDefFoundError` at runtime. If you want to avoid using JAI, you can always try using my [TIFF plugin for ImageIO](https://github.com/haraldk/TwelveMonkeys#aldusadobe-tagged-image-file-format-tiff). – Harald K Aug 04 '14 at 11:51
  • `NoClassDefFoundError` isn't a rational motivation for not wanting to use JAI or JAIImageIO APIs. It would be more to the point to solve the current problem, rather than swithc to another unknown technology and whatever unknown problems come with it. – user207421 Aug 20 '14 at 08:01

1 Answers1

-1

JAI is an extension to the JDK; you have to install it. See http://download.java.net/media/jai/builds/release/1_1_3/INSTALL.html .

Make sure you have installed it correctly.

user207421
  • 305,947
  • 44
  • 307
  • 483
André Wéber
  • 74
  • 1
  • 1
  • my jar was corrupted so not able to make it.. downloaded correct one start working Thanks – user23385 Nov 03 '14 at 04:53
  • 1
    this is not really the answer to the actual question. it solves user23385s problem, but does not solve reading a tiff without JAI :( – manu Mar 13 '15 at 08:03