Hi Thomas, I was on the wrong track trying to build a GVT in the context of anything other than a document, I see exactly your point.
The 'g' elements are exactly the right size, I was confused because I wasn't correctly translating the child graphics node. What I do to rasterize any part of the document is to build the GVT from the document, then I can do the following for any GraphicsNode (at least, I've tried it with Canvas, Composite, Shape and Image). A graphicsNode is already defined from some part of the GVT: AffineTransform transform = AffineTransform.getTranslateInstance(-(graphicsNode.getBounds().getX()), -(graphicsNode.getBounds().getY())); graphicsNode.setTransform(transform); BufferedImage image = new BufferedImage( (int) graphicsNode.getBounds().getWidth(), (int) graphicsNode.getBounds().getHeight(), BufferedImage.TYPE_INT_RGB); Graphics2D graphics = image.createGraphics(); graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); graphicsNode.paint(graphics); ImageIO.write(image, "jpeg", new File("c:/tmp/test.jpeg")); I should probably get a copy of the original transform from the graphicsNode and replace it once I'm done writing the image. It was because I wasn't applying the translation that all of the images were coming out black (well, they were actually just different sizes of the top left hand corner of the image which happened to be blank). Should it be up to the user to set this translation transform for each GraphicsNode? Couldn't this be set on the GraphicsNode by the bridge when it's created or would that alter the whole tree? thanks, Jon -----Original Message----- From: Thomas DeWeese [mailto:[EMAIL PROTECTED] Sent: 01 March 2005 10:41 To: Batik Users Subject: Re: building GVT from elements Hi Jonathan, Jonathan Gray wrote: > Does batik internally use the builder to build GraphicsNodes or does it > always use Documents? They are always built in the context of a document, otherwise CSS won't work properly. > I have been using this to build child GraphicsNodes of an SVG document > so that I can rasterize fragments of it. However, so far its been > pretty unsuccessful because all of the 'g' elements have been the wrong > size and all the shape nodes (mostly 'polygon') have appeared as black > images (although they do seem to be the right size). I don't think I understand what you mean by "the 'g' elements have been the wrong size". The 'g' elements are aways the union of their descendants bounds. > Can anyone think of a good way to rasterize parts of an SVG document, or > a path to develop this functionality with batik? I would do one of two things, one would be to build the complete GVT tree and then call paint directly on the GraphicsNode that I was interested in having painted or I might set all the other 'branches' of the SVG document to be visibility="hidden" or display="none". At the very least you might consider building a 'sub' document that includes all the nodes from the root of the SVG document to the element of interest. Without this the 'context' for the subtree many things could be lost (I would suspect that this is why the polygons are black, although that might also be because the coloring is done with a CSS style sheet?) it all depends heavily on the structure of the document in question. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]