在Java中将位图图像转换为未压缩的tif图像 [英] Convert a bitmap image to an uncompressed tif image in Java
问题描述
我正在尝试将位图图像转换为未压缩的tif文件,以便与Tesseract OCR引擎一起使用。
I'm trying to convert a bitmap image into an uncompressed tif file for use with the Tesseract OCR engine.
我可以使用此方法生成压缩的tif文件...
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"));
当jpg更改为tif时会产生一个空的tif文件,因为这些文件被处理在Java高级成像(JAI)中。
This produces an empty tif file when the "jpg" is changed to tif as these files are dealt with in Java Advanced Imaging (JAI).
如何创建未压缩的tif图像?我应该解压缩上面代码生成的tif图像还是有其他方法来处理转换过程?
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.
谢谢
kingh32
推荐答案
您可以使用 ImageWriteParam
来禁用压缩:
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);
这篇关于在Java中将位图图像转换为未压缩的tif图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!