【发布时间】:2019-04-16 20:58:41
【问题描述】:
目前我正在学习 SVG,现在我想通过 Java API 绘制 SVG。目前我正在研究 Apache Batik,但请随时提出不同的解决方案。
我现在要做的是绘制一个描述填充四分之一圆的路径元素。使用纯 SVG 和文本编辑器,这没有问题,看起来像这样:
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<path d="M50,50 L30,50 A20,20 0 0,1 50,30 z"
style="fill:black;"
/>
我怎样才能对蜡染做同样的事情。在文档中,我只能找到 drawArc 方法,但这只会绘制四分之一圆的方舟部分,如下所示:
公共类 SoExampleMain {
public static void main(String[] args) throws IOException {
// Get a DOMImplementation.
DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
// Create an instance of org.w3c.dom.Document.
String svgNS = "http://www.w3.org/2000/svg";
Document document = domImpl.createDocument(svgNS, "svg", null);
// Create an instance of the SVG Generator.
SVGGraphics2D g = new SVGGraphics2D(document);
g.drawArc(30, 30, 40, 40, 90, 90);
// we want to use CSS style attributes
boolean useCSS = true;
// Finally, stream out SVG to the standard output using
// UTF-8 encoding.
Writer out = new OutputStreamWriter(new FileOutputStream(new File("C:\\Users\\Scyla101\\Desktop\\batik-test.svg")), "UTF-8");
g.stream(out, useCSS);
}
}
有没有办法获得与使用 path 元素在常规 SVG 中获得的结果相同的结果。
作为一个辅助节点,是否有适用于 Batik API 的好教程?
问候
【问题讨论】: