JAI Problem - TIFF Image to JPEG conversion

S

surendra

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();
}
 
Joined
Jun 21, 2008
Messages
1
Reaction score
0
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:
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,701
Latest member
XavierQ83

Latest Threads

Top