java - Can I create a JSVGCanvas without an svg file? -
looking through documentation jsvgcanvas
, seems might not able this. however, makes lot of sense possible. how can create jsvgcanvas
string
variable instead of file
?
my idea following:
string svg = "svg data"; jframe frame = new jframe(); jsvgcanvas canvas = new jsvgcanvas(); canvas.setcontentsfromstring(svg); frame.add(canvas); frame.setvisible(true);
i know create temporary file , set contents of jsvgcanvas
file, i'd rather avoid that. perhaps extend file
, override methods?
note: using jython, think relevant java well, hence i'm using both tags. i'd prefer solution in java, jython solution work
yes, can:
string parser = xmlresourcedescriptor.getxmlparserclassname(); saxsvgdocumentfactory factory = new saxsvgdocumentfactory(parser); svgdocument document = factory.createsvgdocument("", new bytearrayinputstream(svg.getbytes("utf-8"))); canvas.setsvgdocument(document);
this works creating svgdocument
via saxsvgdocumentfactory
. saxsvgdocumentfactory
has method createsvgdocument(string, inputstream)
, string supposed uri file inputstream
represents. however, abuse , give empty string, , make inputstream
stream our svg-data string.
using ""
might throw exception being no protocol, depending on version of batik. if that's case, try "file:///"
, is, give uri lie. may want use actual uri; you'd need figure out valid 1 give batik
Comments
Post a Comment