使用Java操作SVG
SVG:可扩展的矢量图。用js可以很方便的操作,用Java appl
et 操作的话就有些麻烦了。
SVG的本质就是XML技术,熟悉XML就是就可以很好搞SVG了。至少知道SVG的原理的,调试程
序的时候有一个很大的优势,深有体会,哈哈。
使用java SVG,使用JFrame用于显示图片
String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory saxf = new SAXSVGDocumentFactory(parser);
System.out.println(f.toURL().toString());
Document doc = saxf.createDocument(f.toURI().toString());
SVGDocument svgdoc = (SVGDocument) doc;
Element anmimateNode = svgdoc.createElement("animate");
anmimateNode.setAttribute("attributeName", "fill"); anmimateNode.setAttribu
te("from", "white");
anmimateNode.setAttribute("to", "red");
anmimateNode.setAttribute("dur", "0.2s");
anmimateNode.setAttribute("fill", "indefinite");
anmimateNode.setAttribute("repeatCount", "0.2s");
Element eeye = svgdoc.getElementById("wheel");
NodeList nl = eeye.getElementsByTagName("circle");
Node node = nl.item(1);
node.appendChild(anmimateNode);
System.out.println(node.getChildNodes().getLength());
svgCanvas.setSVGDocument(svgdoc);。
|