如何以无损方式从JPEG图像创建金字塔平铺TIFF

时间:2011-07-29 02:02:12

标签: java compression jpeg tiff lossless

我需要使用无损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();
    }
}

1 个答案:

答案 0 :(得分:0)

Ossim在命令行中运行良好,但我看到它也有JNI binding