Convert a bitmap image to an uncompressed tif image in Java

自闭症网瘾萝莉.ら 提交于 2019-12-07 09:04:34

问题


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


回答1:


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:


Some time before i was facing the problems with tiff images reading and conversion with jai. I found that it need to install support for working with tiff images in jai, then it works fine for me u can also get it 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 over a jvm then it will also work for you. you can also have a look here Java / JAI - save an image gray-scaled



来源:https://stackoverflow.com/questions/3845376/convert-a-bitmap-image-to-an-uncompressed-tif-image-in-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!