Add/remove ImageReader from jar to ImageIO-registry

感情迁移 提交于 2019-12-11 13:39:32

问题


In jar jai_imageio.jar there is class:

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

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);
}

results the following output:

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

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

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?

Background

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.


回答1:


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).

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).



来源:https://stackoverflow.com/questions/11985945/add-remove-imagereader-from-jar-to-imageio-registry

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!