ImageIO解析TIF转为JPEG

1
2
3
4
5
static{
IIORegistry registry = IIORegistry.getDefaultInstance();
registry.registerServiceProvider(new com.sun.media.imageioimpl.plugins.tiff.TIFFImageWriterspi());
registry.registerServiceProvider(new com.sun.media.imageioimpl.plugins.tiff.TIFFImageReaderspi();
}

另一种方式,META-INF/service下已经有了服务注册的信息,没有注册上是由于maven打包的时候使用覆盖的方式,有重名的文件会覆盖。使用maven插件可以避免此问题。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<plugin>				
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/services/javax.imageio.spi.ImageReaderSpi</resource>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>