[英]Generate JPG from SVG using Apache Batik
我正在尝试将.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,请告诉我。
好吧,我现在找到了解决我的问题的方法。 似乎Batik 1.8 (我使用过)不能正常工作(或者至少不能像他们在 API 页面上所说的那样工作。
我现在使用Batik 1.7,效果很好。 所以现在一切都很好,对于想要使用 Batik 的每个人:我建议您使用 1.7,因为文档不是关于 1.8。
如果您将batik-codec
添加到maven
而不是transcoder
这可以解决。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.