Search code examples
javajavax.imageiojpeg2000

I can't use jai-imageio / jai-imageio-jpeg2000


I am trying to use the community fork of the original java.net project jai-imageio-core (which is no longer available upstream), and use it to write jpeg2000 images. The fork for the core imageIO project is available at: here

And the jpeg2000 spi is at: here

I am just trying to run one of the simplest tests for the jpeg2000 spi:

    IIORegistry registry = IIORegistry.getDefaultInstance();
    registry.registerServiceProvider(new com.github.jaiimageio.jpeg2000.impl.J2KImageReaderSpi());
    
    String[] suff = ImageIO.getWriterFileSuffixes();
    Iterator<ImageWriter> writers = ImageIO.getImageWritersBySuffix("jp2");

But it does not find any ImageWriter which can handle this jp2 extension. However, it is correctly defined in the J2KImageReaderSpiclass.

What I detected is that the JVM (I'm using Java 8) does not use the fork for imageio but the JDK default imageio version. Which might be the reaosn for my problem. What did I do wrong?


Solution

  • registry.registerServiceProvider(new J2KImageReaderSpi());
    

    What did I do wrong?

    You were registering the J2KImageReaderSpi (Reader), while you are were looking for the J2KWriter (Writer).

    If you want to write JPEG2000, try registering the J2KImageWriterSpi instead:

    registry.registerServiceProvider(new J2KImageWriterSpi());
    

    Although I think this should just happen automatically if the JARs contain the correct META-INF/services entries, and you place the JAR on the class path.