JAI Problem - TIFF Image to JPEG conversion

Discussion in 'Java' started by surendra, Feb 19, 2004.

  1. surendra

    surendra Guest

    Hi,

    I am trying to convert TIFF Image to JPEG. For some of the images I
    get the following exception.

    My first thought was may be the image is not correct. I can view
    the Tiff image ok and I can convert to PNG as well.

    Please post here if you have any info on this exception.

    Regards,
    Suren

    EXCEPTION DETAILS:
    java.lang.ArrayIndexOutOfBoundsException: 44544
    at com.sun.media.jai.util.SunTileScheduler.scheduleTile(SunTileScheduler.java:941)
    at javax.media.jai.OpImage.getTile(OpImage.java:1139)
    at javax.media.jai.PlanarImage.getData(PlanarImage.java:2220)
    at javax.media.jai.PlanarImage.getData(PlanarImage.java:2029)
    at javax.media.jai.RenderedOp.getData(RenderedOp.java:2277)
    at com.sun.media.jai.codecimpl.JPEGImageEncoder.encode(JPEGImageEncoder.java:180)

    SOURCE CODE:
    try{

    RenderedOp source = JAI.create("fileload", filename);

    FileOutputStream stream = null;

    stream = new FileOutputStream(jpegFileName );
    com.sun.media.jai.codec.JPEGEncodeParam JPEGparam = new
    com.sun.media.jai.codec.JPEGEncodeParam();
    ImageEncoder encoder =
    ImageCodec.createImageEncoder("jpeg",stream,JPEGparam);

    encoder.encode(source);
    }catch(Exception e){
    e.printStackTrace();
    }
    surendra, Feb 19, 2004
    #1
    1. Advertising

  2. surendra

    dipakPardesi

    Joined:
    Jun 21, 2008
    Messages:
    1
    tiff to png conversion

    if u want to convert tiff to jpeg, check out followin code...
    i wrote :stupido: this 4 tiff to png conversion ...



    public static RenderedImage[] readMultiPageTiff(String *fileName*)throws IOException{
    File file = new File(fileName);
    SeekableStream seekableStream = new FileSeekableStream(file);
    ImageDecoder decoder = ImageCodec.createImageDecoder("tiff", seekableStream, null);
    int numPages = decoder.getNumPages();
    RenderedImage image[]= new RenderedImage[numPages];
    int count = 0;
    for(int i=0;i<decoder.getNumPages();i++){
    image = decoder.decodeAsRenderedImage(i);
    count++;
    }

    String newFolderName;
    String s3 = fileName;
    String [] temp = null;
    temp = s3.split("\\.");

    int j;
    j = 0;
    do{
    newFolderName = temp[j];
    String spoonFeeding = newFolderName;
    File f = new File(spoonFeeding);
    f.mkdirs();
    j++;
    }while (j<1);

    for (int i = 0; i < count; i++) {
    RenderedImage page = decoder.decodeAsRenderedImage(i);
    File fileObj = new File(newFolderName+"/" + (i+1) + ".png");
    System.out.println("Saving " + fileObj.getCanonicalPath());
    ParameterBlock parBlock = new ParameterBlock();
    parBlock.addSource(page);
    parBlock.add(fileObj.toString());
    parBlock.add("png");
    RenderedOp renderedOp = JAI.create("filestore",parBlock);
    renderedOp.dispose();
    }
    return image;
    }

    jus pass the path of file to method... method read that tiff image ... create a new folder in same path names input...
    and convert the tiff pages to png image...
    its running fine..... :driver:


    if u want d same.. thn change d code as per ur requirement ...
    i use doWhile loop..
    this code cause single time i passd no. of tiff images 8)

    ..
    ok.. enjoy ...:sleep:
    dipakPardesi, Jun 21, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chuck Taylor
    Replies:
    1
    Views:
    8,275
    Chuck Taylor
    Sep 4, 2003
  2. cyril
    Replies:
    1
    Views:
    778
    cyril
    Sep 8, 2003
  3. Roland
    Replies:
    0
    Views:
    1,042
    Roland
    May 12, 2004
  4. dwilson
    Replies:
    0
    Views:
    1,199
    dwilson
    Apr 8, 2005
  5. voncroy14
    Replies:
    0
    Views:
    1,040
    voncroy14
    Jul 17, 2009
Loading...

Share This Page