我正在完成一个可以压缩多页 tiff 图像的 java 应用程序。问题是,如果我将它作为 .jar 文件运行,它在我的 IDE 内部以及同一台计算机上的本地环境中都可以正常工作,但是如果我尝试在另一台也安装了 java 的计算机上运行它,它会压缩 tiff 文件,但这些图像不再可见。单击它们会为 Windows 图像查看器显示“无可用预览”。这可能是什么原因造成的?我用于压缩多页tiff的具体方法如下:
public synchronized void compress() throws IOException
{
System.out.println("NUMpAGES: " + numPages);
if(this.getSrcImageFile().length()<SIZE_THRESHOLD){
this.closeAllStreams();
return;
}
this.initOutStreams();
this.setImageEncoder(ImageCodec.createImageEncoder("tiff", this.getOutputStream(), null));
int compressionAlgorithm;
if(bitDepth == 1 || bitDepth == 8)
{
/*Cant use JPEG_TTN2 with images that have less than 8-bit samples/only have a bit-depth of 1.*/
compressionAlgorithm = TIFFEncodeParam.COMPRESSION_DEFLATE;
encodeParams.setCompression(compressionAlgorithm); //redundant with line above
}
else
{
System.out.println("Attempting to compress using JPEG_TTN2 with bit depth: " + bitDepth);
compressionAlgorithm = TIFFEncodeParam.COMPRESSION_JPEG_TTN2;
encodeParams.setCompression(compressionAlgorithm); //redundant with line above
}
this.setImageEncoder(ImageCodec.createImageEncoder("tiff", this.getOutputStream(), encodeParams));
Vector vector = new Vector();
if(numPages == 1){
for(int i = 0; i < numPages - 1; i ++) //i < bufferedImages.length OLD
{
System.out.println(i);
vector.add((bufferedImages[i]));
}
}else{
System.out.println("Using second case");
for(int i = 0; i < numPages; i ++)
{
System.out.println("Adding to vector image for file " + this.getSrcImagePath() + " " + i);
vector.add((bufferedImages[i]));
}
}
System.out.println("Buffered Images size: " + bufferedImages.length);
Iterator vecIter = vector.iterator();
if(numPages > 1){
vecIter.next();
}
encodeParams.setExtraImages(vecIter);
this.getImageEncoder().encode(bufferedImages[0]);
closeAllStreams();
}