我需要使用无损jpeg操作(即jpegtran裁剪)从大JPEG图像创建JPEG压缩切片的平铺金字塔TIFF文件。是否有任何工具或Java代码来执行此类操作?
目前我正在使用我的Java代码创建平铺金字塔TIFF,但它是以有损方式执行的:
public static void writeTiff(RenderedOp src, File dstFile, float jpegQuality, int tileSize, int pyramid, String interpolation) throws IOException {
dstFile.getParentFile().mkdirs();
TIFFImageWriterSpi imageWriterSpi = new TIFFImageWriterSpi();
TIFFImageWriter imageWriter = (TIFFImageWriter)imageWriterSpi.createWriterInstance();
ImageOutputStream out = new FileImageOutputStream(dstFile);
try {
imageWriter.setOutput(out);
imageWriter.prepareWriteSequence(null);
BufferedImage img = null;
for(int i=0; i<pyramid; i++) {
img = img==null ? src.getAsBufferedImage() : JAIUtils.scale(img, 0.5F, interpolation).getAsBufferedImage();
TIFFImageWriteParam imageWriteParam = (TIFFImageWriteParam)imageWriter.getDefaultWriteParam();
if (tileSize>0 && (img.getWidth()>tileSize || img.getHeight()>tileSize)) {
imageWriteParam.setTilingMode(ImageWriteParam.MODE_EXPLICIT);
imageWriteParam.setTiling(tileSize, tileSize, 0, 0);
}
if (jpegQuality > 0) {
imageWriteParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT );
imageWriteParam.setCompressionType("JPEG");
imageWriteParam.setCompressionQuality(jpegQuality);
}
imageWriter.writeToSequence(new IIOImage(img, null, null), imageWriteParam );
}
imageWriter.endWriteSequence();
} finally {
out.close();
}
}