xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oliver Mihatsch <o...@knaeul.de>
Subject Re: Render animations manually into Graphics2D
Date Thu, 19 Mar 2009 20:57:34 GMT
Hi,

I'm a step further using the SVGAnimationEngine, but the resulting Image 
is empty because nothing is drawn :-(.
With Squiggle the SVG animation is correctly displayed.

This is the code I'm using:

        String parser = XMLResourceDescriptor.getXMLParserClassName();
        SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
       
        SVGDocument doc = 
f.createSVGDocument(findFile(pFilename).toString());
        UserAgentAdapter userAgent = new UserAgentAdapter();
        BridgeContext ctx = new BridgeContext(userAgent);
       
        //parse document
        GVTBuilder builder = new GVTBuilder();
        GraphicsNode gvtRoot = null ;
        try {
            ctx.setDynamicState(BridgeContext.DYNAMIC);
            gvtRoot = builder.build(ctx, doc);
        }
        catch (BridgeException e) {
            new IOException("Error loading svg image", e);
        }
       
        //create animation engine
        ctx.setAnimationLimitingNone();
        SVGAnimationEngine animationEngine = ctx.getAnimationEngine();
       
        //draw image
        if(!mAnimationEngine.hasStarted()) {
            mAnimationEngine.start(System.currentTimeMillis());
        } else {
            mAnimationEngine.setCurrentTime(System.currentTimeMillis());
        }
        gvtRoot.paint(pGraphics);


Regards,
Oliver


Oliver Mihatsch schrieb:
> Hi,
>
> for a small java game I would like to pre-render SVG Animations into 
> BufferedImages.
> Rendering should run in the same thread, without using classes which 
> starts an own thread like the UpdateManager.
>
> How can I apply the animation manually on the tree?
>
> This is the code I'm using at the moment:
>
>        //load image
>        String parser = XMLResourceDescriptor.getXMLParserClassName();
>        SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
>              Document doc = 
> f.createDocument(findFile(pFilename).toString());
>        UserAgentAdapter userAgent = new UserAgentAdapter();
>        BridgeContext ctx = new BridgeContext(userAgent);
>        GVTBuilder builder = new GVTBuilder();
>
>        GraphicsNode gvtRoot = null ;
>        try {
>            ctx.setDynamicState(BridgeContext.DYNAMIC);
>            gvtRoot = builder.build(ctx, doc);
>        }
>        catch (BridgeException e) {
>            new IOException("Error loading svg image", e);
>        }
>
>        //draw static image
>        Graphics2D graphics = (Graphics2D) pGraphics.create();
>        graphics.transform(mTransformation);
>        gvtRoot.paint(graphics);
>
>
> Thanks in advance,
> Oliver
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Mime
View raw message