I think this is possible, at least on modern browsers (FF4+, Chrome,
Opera), if you use the fact that <img> can use SVG as their sources on
these browsers.
There are no built-in APIs for this in lib-gwt-svg yet, but if you
combine OMSVGElement.getMarkup() (which gives you a serialized XML
version of your SVG element), data urls, and img, this works (at least
on FF where I have tested it).
This is what it would look like:
public class ExportToImage implements EntryPoint {
public void run() {
OMSVGDocument document = OMSVGParser.currentDocument();
OMSVGSVGElement svg = document.createSVGSVGElement();
svg.getStyle().setWidth(300, Unit.PX);
svg.getStyle().setHeight(300, Unit.PX);
OMSVGCircleElement circle = document.createSVGCircleElement(150,150,120);
circle.getStyle().setSVGProperty("fill", SVGConstants.CSS_YELLOW_VALUE);
circle.getStyle().setSVGProperty("stroke", SVGConstants.CSS_BLACK_VALUE);
svg.appendChild(circle);
String url = "data:image/svg+xml;base64," + base64encode(svg.getMarkup());
Image img = new Image(url);
RootPanel.get().add(new SVGImage(svg));
RootPanel.get().add(img);
}
private static native String base64encode(String str) /*-{
return $wnd.btoa(str);
}-*/;
@Override
public void onModuleLoad() {
run();
}
}
Cheers
Lukas
On Fri, Jun 24, 2011 at 9:57 AM, Venugopal V <wenu...@gmail.com> wrote: