You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Oliver Mihatsch <ol...@knaeul.de> on 2009/03/18 20:40:07 UTC
Render animations manually into Graphics2D
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
Re: Render animations manually into Graphics2D
Posted by robiwan <ro...@xponaut.se>.
Oliver Mihatsch wrote:
>
> Ok, found the last piece, updating the time is a little bit strange.
> Using this code to update the animation engine, the animation works
> finally :-)
>
> if(!mAnimationEngine.hasStarted()) {
> mAnimationEngine.start(System.currentTimeMillis());
> mStartTime = System.currentTimeMillis();
> } else {
> mAnimationEngine.setCurrentTime((System.currentTimeMillis()
> - mStartTime) / 1000f);
> }
>
Great! But how does the gvtRoot.paint(...) call result in a BufferedImage ?
Care to share that too :) ?
TIA
/Rob
--
View this message in context: http://www.nabble.com/Render-animations-manually-into-Graphics2D-tp22586961p23536127.html
Sent from the Batik - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: Render animations manually into Graphics2D
Posted by Helder Magalhães <he...@gmail.com>.
Hi Olivier,
> Ok, found the last piece, updating the time is a little bit strange.
> Using this code to update the animation engine, the animation works finally
> :-)
Great you were able to fix your problem, and thanks for sharing the
solution! :-)
Now, I'm also not very familiar with Batik internals but it sounds
like this could become useful for bug 44654 [1].
Best regards,
Helder Magalhães
[1] https://issues.apache.org/bugzilla/show_bug.cgi?id=44654
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: Render animations manually into Graphics2D
Posted by Oliver Mihatsch <ol...@knaeul.de>.
Ok, found the last piece, updating the time is a little bit strange.
Using this code to update the animation engine, the animation works
finally :-)
if(!mAnimationEngine.hasStarted()) {
mAnimationEngine.start(System.currentTimeMillis());
mStartTime = System.currentTimeMillis();
} else {
mAnimationEngine.setCurrentTime((System.currentTimeMillis()
- mStartTime) / 1000f);
}
Got that code snippet from TimedDocumentRoot.convertWallclockTime which
is not accessible from outside.
Best regards,
Oliver
Oliver Mihatsch schrieb:
> 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
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: Render animations manually into Graphics2D
Posted by Oliver Mihatsch <ol...@knaeul.de>.
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