Issue in getImageWritersByFormatName for Tiff. Getting image writer

后端 未结 2 481
日久生厌
日久生厌 2021-01-25 11:47

I am trying to convert PDF to tif images. I use following code to get the image writers by format.

Iterator writers = ImageIO.getImageWritersB         


        
相关标签:
2条回答
  • 2021-01-25 12:08

    Tiff support is provided by the Java Advanced Imaging plugin jai_core.jar.

    In order to work correctly, the jar file needs to be added to the JVM's ext directory, otherwise it won't register properly

    0 讨论(0)
  • 2021-01-25 12:29

    I met the same issue and found the root cause.

    Let me summarize first, the issue does not occur in eclipse on dev machine, and it occurs on Tomcat server.

    The root cause is that the imageio uses SPI, and there is a basic implementation in JDK (please refer to rt.jar, we can find it with two plugins for bmp and jpeg.) while the plugins we wants are in jai_imageio.jar.

    With default configuration, Tomcat scans the one in rt.jar for plugins during initialization for ImageIO. Later when the application runs, the jai_imageio.jar won't be scanned.

    As a result the plugins in jai_imageio.jar are not available. When running in dev machine, jai_imageio.jar is scanned.

    There are several solutions as listed below, i would recommend the first one as it fits the design intention of ImageIO.

    1. without changing the tomcat default configuration, re-scan the jar.

      static { ImageIO.scanForPlugins(); }

    2. changing the tomcat configuration, so tomcat won't initialize ImageIO. edit file /conf/server.xml,add appContextProtection="false" like following:

    <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" appContextProtection="false" />

    With suchconfiguration, tomcat won't call ImageIO.getCacheDirectory in JreMemoryLeakPreventionListener, so ImageIO is not initialized until our codes runs.

    0 讨论(0)
提交回复
热议问题