Skip to main content

TIFF to JPEG conversion, converted JPEG file is not correct.

No replies
NjkHappy2008
Offline
Joined: 2011-06-26
Points: 0

Hello Every One,

I try to convert TIFF to JPEG, but converted JPEG file is not correct, the below is my code, hope someone can help me, thanks.

public static void testTif2JPG(String tiff, String output) {
File tiffFile = new File(tiff);
SeekableStream s;
FileOutputStream fos = null;
try {
s = new FileSeekableStream(tiffFile);
TIFFDecodeParam param = new TIFFDecodeParam();
ImageDecoder dec = ImageCodec.createImageDecoder("tiff", s, param);
RenderedImage op = dec.decodeAsRenderedImage(0);
fos = new FileOutputStream(output);
JPEGImageEncoder jpeg = JPEGCodec.createJPEGEncoder(fos);
jpeg.encode(op.getData());
fos.close();
} catch (IOException e) {
if (null != fos) {
try {
fos.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
e.printStackTrace();
}
}