本文介绍了将Jar中的ImageReader添加/删除到ImageIO-registry的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jar jai_imageio.jar中有一个类:

In jar jai_imageio.jar there is class:

com.sun.media.imageioimpl.plugins.jpeg.CLibJPEGImageReader

因此,我将jai_imageio.jar(和jai_core.jar,jai_codec.jar)添加到类路径中.但是该类似乎不可用于ImageIO.所以这段代码:

So i add jai_imageio.jar (and jai_core.jar, jai_codec.jar) to classpath. But this class seems not to be accessable for ImageIO. So this code:

ImageIO.scanForPlugins();
IIORegistry.getDefaultInstance().registerApplicationClasspathSpis();
Iterator<ImageReader> ir = ImageIO.getImageReadersByFormatName("jpeg");
while(ir.hasNext()) {
    ImageReader r = ir.next();
    System.out.println("can read raster: " + r.canReadRaster());
    System.out.println(r);
}

结果如下:

can read raster: true
com.sun.imageio.plugins.jpeg.JPEGImageReader@54520eb

在99%的计算机上.但是在一台机器上,它会产生以下输出:

on 99% of machines. But on one machine it results this output:

Can read raster: false
com.sun.media.imageioimpl.plugins.jpeg.CLibJPEGImageReader@163e9a1
Can read raster: true
com.sun.imageio.plugins.jpeg.JPEGImageReader@10cecb2

为什么会发生?我应该做更多的事情,只是将带有ImageIO插件的jar放在classpath上?我可以以某种方式从ImageIO-Registry卸载ImageReader吗?

Why does it happens? Should i do more as just put the jar with ImageIO plugins on classpath? Can i somehow unload an ImageReader from ImageIO-Registry?

背景

实际上,我的问题是一些外部不变的代码应该使用ImageIO Registry中的第一个ImageReader来读取栅格.但不幸的是,在一台PC上,第一个ImageReader是CLibJPEGImageReader. JDK和类路径相同,因此如果在类路径上放置一个带有插件的jar足以使其对ImageIO可见,则CLibJPEGImageReader应该始终在注册表中.

Actually my problem is that some external unchangeable code is supposed to use the first ImageReader from ImageIO Registry to read the raster. But unfortunately on one PC the first ImageReader is CLibJPEGImageReader. The JDK and classpath are identical, so CLibJPEGImageReader should be always in registry, if put a jar with plugin on classpath is enough to make it visible for ImageIO.

推荐答案

最可能的原因是您正在使用CLibJPEGImageReader的计算机上已安装了JAI ImageIO库( http://java.net/projects/jai-imageio ).

The most likely reason is that the machine you're using CLibJPEGImageReader on has the JAI ImageIO library installed (http://java.net/projects/jai-imageio).

为什么其他方法不起作用(除了显而易见的原因)是因为您已在64位系统上安装了32位版本的库,而未安装multilib库( https://wiki.archlinux.org/index.php/Arch64_FAQ ).

Why the others don't work (apart from the obvious) is because you've installed the 32-bit version of the libraries on a 64-bit system and not installed the multilib libraries (https://wiki.archlinux.org/index.php/Arch64_FAQ).

这篇关于将Jar中的ImageReader添加/删除到ImageIO-registry的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 09:39