JAVA:SVG 到 JPG 转换器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15256112/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JAVA: SVG to JPG converter
提问by mohammad
is there any libraries to convert SVGto JPG? else than BATIK? i used BATIKbut i found some problems like this exception :
是否有任何库可以将SVG转换为JPG?除了BATIK?我使用了BTIK但我发现了一些问题,比如这个异常:
java.lang.NullPointerException at org.apache.batik.css.engine.CSSEngine.getCascadedStyleMap(CSSEngine.java:684) at org.apache.batik.css.engine.CSSEngine.getComputedStyle(CSSEngine.java:755) at org.apache.batik.bridge.CSSUtilities.getComputedStyle(CSSUtilities.java:96) at org.apache.batik.bridge.CSSUtilities.convertDisplay(CSSUtilities.java:509) at org.apache.batik.bridge.GVTBuilder.buildGraphicsNode(GVTBuilder.java:176) at org.apache.batik.bridge.GVTBuilder.buildComposite(GVTBuilder.java:148) at org.apache.batik.bridge.GVTBuilder.build(GVTBuilder.java:76) at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(SVGAbstractTranscoder.java:165) at org.apache.batik.transcoder.image.ImageTranscoder.transcode(ImageTranscoder.java:86) at org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(XMLAbstractTranscoder.java:132)
java.lang.NullPointerException at org.apache.batik.css.engine.CSSEngine.getCascadedStyleMap(CSSEngine.java:684) at org.apache.batik.css.engine.CSSEngine.getComputedStyle(CSSEngine.java:755) at org. apache.batik.bridge.CSSUtilities.getComputedStyle(CSSUtilities.java:96) 在 org.apache.batik.bridge.CSSUtilities.convertDisplay(CSSUtilities.java:509) 在 org.apache.batik.bridge.GVTBuilder.buildGraphicsNode(GVTBuilder. java:176) 在 org.apache.batik.bridge.GVTBuilder.buildComposite(GVTBuilder.java:148) 在 org.apache.batik.bridge.GVTBuilder.build(GVTBuilder.java:76) 在 org.apache.batik.transcoder .SVGAbstractTranscoder.transcode(SVGAbstractTranscoder.java:165) 在 org.apache.batik.transcoder.image.ImageTranscoder.transcode(ImageTranscoder.java:86) 在 org.apache.batik.transcoder.XMLAbstractTranscoder。转码(XMLAbstractTranscoder.java:132)
this is my code :
这是我的代码:
JPEGTranscoder transcoder = new JPEGTranscoder();
transcoder.addTranscodingHint(JPEGTranscoder.KEY_XML_PARSER_CLASSNAME,
"org.apache.crimson.parser.XMLReaderImpl");
transcoder.addTranscodingHint(JPEGTranscoder.KEY_QUALITY,
new Float(1.0));
TranscoderInput input = new TranscoderInput(new FileInputStream("C:/Taha/SmartPlannerNew/rectangles.svg"));
OutputStream ostream = new FileOutputStream("C:/Taha/SmartPlannerNew/out.jpg");
TranscoderOutput output = new TranscoderOutput(ostream);
try {
transcoder.transcode(input, output);
} catch (TranscoderException e) {
System.out.println("error***************************************************************************************************************************");
e.printStackTrace();
}
System.out.println("done.");
ostream.close();
System.exit(0);
can any one help me please ?
有人可以帮我吗?
采纳答案by mohammad
my mistake was that i was using different versions of jar files i deleted all my jars and downloaded a new set of jars from the same
我的错误是我使用了不同版本的 jar 文件,我删除了所有 jar 并从同一个 jar 下载了一组新的 jar
回答by trognanders
Batik is exactly what you are looking for, is totally stable, and there really is not much else.
蜡染正是您要找的,完全稳定,除此之外别无他物。
You can read the handy official tutorial on using the transcoder portion of batik: http://xmlgraphics.apache.org/batik/using/transcoder.html
您可以阅读有关使用蜡染转码器部分的方便的官方教程:http: //xmlgraphics.apache.org/batik/using/transcoder.html
If you are still having trouble, try posting the code that you are using that causes the error, and a complete stack trace. Somebody here will be able to help you.
如果您仍然遇到问题,请尝试发布您正在使用的导致错误的代码以及完整的堆栈跟踪。这里有人可以帮助你。