views:

26

answers:

1

Hello

I'm trying to convert a bitmap image into an uncompressed tif file for use with the Tesseract OCR engine.

I can use this method to produce a compressed tif file...

final BufferedImage bmp = ImageIO.read(new File("input.bmp"));
ImageIO.write(bmp, "jpg", new File("output.tif"));

This produces an empty tif file when the "jpg" is changed to tif as these files are dealt with in Java Advanced Imaging (JAI).

How can I create an uncompressed tif image? Should I decompress the tif image produced from the above code or is there another way to handle the conversion process?

Any examples provided would be much appreciated.

Thanks

kingh32

A: 

You can use ImageWriteParam to disable compression:

TIFFImageWriterSpi spi = new TIFFImageWriterSpi();
ImageWriter writer = spi.createWriterInstance();
ImageWriteParam param = writer.getDefaultWriteParam();
param.setCompressionMode(ImageWriteParam.MODE_DISABLED);

ImageOutputStream ios = ImageIO.createImageOutputStream(new File("output.tif"));
writer.setOutput(ios);
writer.write(null, new IIOImage(bmp, null, null), param);
Grodriguez
Thank you this works!
Kingh32