比较简单,主要使用batik包里的batik-transcoder模块,网上的教程引的包太多了,只是转化的话,这个包就够了。你们引用的时候,记得查一下version,之前我引用的包太老了,项目就起不来了。
//pom引入该包
<dependency>
<groupId>batik</groupId>
<artifactId>batik-transcoder</artifactId>
<version>1.6-1</version>
</dependency>
使用这个方法即可
public void convertSvg2Png(File svg, File png) throws IOException, TranscoderException
{
InputStream in = new FileInputStream(svg);
OutputStream out = new FileOutputStream(png);
out = new BufferedOutputStream(out);
Transcoder transcoder = new PNGTranscoder();
try {
TranscoderInput input = new TranscoderInput(in);
try {
TranscoderOutput output = new TranscoderOutput(out);
transcoder.transcode(input, output);
} finally {
out.close();
}
} finally {
in.close();
}
}