我正在完成一个可以压缩多页tiff图像的java应用程序。问题是,如果我将其作为.jar文件运行,它在我的集成开发环境中以及同一台计算机上的本地环境中都工作得很好,但是如果我尝试在另一台安装了java的计算机上运行它,它会压缩tiff文件,但这些图像不再可见。单击它们将显示windows图像查看器的“无预览可用”。这可能是什么原因造成的?我用来压缩多页tiffs的具体方法如下:
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();
}发布于 2013-10-28 21:46:10
我将重复@mabi在第一条评论中说的话(也是目前为止唯一好的)
JDK并不附带
AFAIK。
我可以把AFAIK升级到'no‘。JAI是,而不是随JRE提供的。
此外,用于处理TIFF的SPIs (服务提供者接口)随JAI一起提供。ImageIO的基于JSE的部分使用SPI来识别文件类型的编码器和解码器。我怀疑这是因为JAI没有安装在第二台计算机上(或者以其他方式添加到应用程序的运行时class-path中)。这就是它失败的原因。
至于为什么它在你的代码中没有明显的失败,这可能是因为它抛出的异常的处理方式。我怀疑他们只是被忽视了。
https://stackoverflow.com/questions/19635397
复制相似问题