我正在尝试将.svg文件转换为.jpg或.png文件。现在我正在尝试使用Apache Batik Transcoder ( Link )。
这是我现在的代码:(来自这里的官方代码)
// Create a JPEG transcoder
JPEGTranscoder t = new JPEGTranscoder();
// Set the transcoding hints.
t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY,
new Float(.8));
// Create the transcoder input.
String svgURI = new File("C:/test.svg").toURL().toString();
TranscoderInput input = new TranscoderInput(svgURI);
// Create the transcoder output.
OutputStream ostream = new FileOutputStream("C:/out.jpg");
TranscoderOutput output = new TranscoderOutput(ostream);
// Save the image.
t.transcode(input, output);
// Flush and close the stream.
ostream.flush();
ostream.close();
System.exit(0);
但它给了我这个错误:
线程“主”org.apache.batik.transcoder.TranscoderException 中的异常:null
封闭的例外:
无效的
在 org.apache.batik.transcoder.image.ImageTranscoder.transcode(未知来源)
在 org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(未知来源)
在 org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(未知来源)
在 SaveAsJPEG.main(SaveAsJPEG.java:27)
我不知道该怎么做,因为这是他们网站上的代码(!)。因此,如果您知道如何解决它或有其他想法如何将我的 .svg 图片转换为 .jpg 和 .png,请告诉我。