0
我需要使用無損jpeg操作(即在jpegtran中裁剪)從大JPEG圖像中創建具有JPEG壓縮圖塊的平鋪金字塔TIFF文件。是否有任何工具或Java代碼執行此類操作?如何以無損方式從JPEG圖像創建金字塔平鋪TIFF
目前我使用我的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();
}
}
謝謝你的提示,我會檢查出來 – wikisky