Convert bitmap to uncompressed tif image in Java

I am trying to convert a bitmap to an uncompressed tif file for use with the Tesseract OCR engine.

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

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

This creates an empty tif file when "jpg" is changed to tif, as these files are considered in Java Advanced Imaging (JAI).

How to create an uncompressed tif image? Should I unzip the tif image obtained from the above code, or is there another way to handle the conversion process?

Any examples submitted would be appreciated.

thanks

kingh32

+4
source share
2 answers

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); 
+2
source

Some time before I ran into problems reading and converting tiff images with jai. I found that he needs to install support for working with tiff images in jai, then it works great for me. U can also get the form here: https://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_Developer-Site/en_US/-/USD/ ViewProductDetail-Start?ProductRef=jaiio-1.0_01-oth-JPR@CDS-CDS _Developer

and install on top of jvm, then it will work for you too. you can also look here Java / JAI - save grayscale image

0
source

All Articles