Hi Philippe,

 

I tried your method. It works.

 

There is another problem. Using example "sunRise.svg", GraphicsNode.paint() method throws the following exception:

 

java.lang.IllegalArgumentException: Width (128) and height (0) must be > 0

            at java.awt.image.SampleModel.<init>(SampleModel.java:105)

            at java.awt.image.SinglePixelPackedSampleModel.<init>(SinglePixelPackedSampleModel.java:125)

            at java.awt.image.Raster.createPackedRaster(Raster.java:656)

            at java.awt.image.Raster.createPackedRaster(Raster.java:431)

            at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:905)

            at sun.java2d.loops.LockableRaster.<init>(LockableRaster.java:130)

            at sun.java2d.loops.RasterOutputManager.convertFrom(RasterOutputManager.java:1463)

            at sun.java2d.loops.RasterOutputManager.performBinaryComposite(RasterOutputManager.java:1372)

            at sun.java2d.loops.RasterOutputManager.compositeSrcDst(RasterOutputManager.java:710)

            at sun.java2d.loops.RasterOutputManager.renderImage(RasterOutputManager.java:479)

            at sun.java2d.SunGraphics2D.renderingPipeImage(SunGraphics2D.java:2223)

            at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:1761)

            at sun.awt.image.BufferedImageGraphics2D.drawImage(BufferedImageGraphics2D.java:512)

            at org.apache.batik.ext.awt.image.GraphicsUtil.drawImage(Unknown Source)

            at org.apache.batik.ext.awt.image.GraphicsUtil.drawImage(Unknown Source)

            at org.apache.batik.gvt.AbstractGraphicsNode.paint(AbstractGraphicsNode.java:448)

            at org.apache.batik.gvt.CompositeGraphicsNode.primitivePaint(CompositeGraphicsNode.java:132)

            at org.apache.batik.gvt.AbstractGraphicsNode.paint(AbstractGraphicsNode.java:415)

            at org.apache.batik.gvt.CompositeGraphicsNode.primitivePaint(CompositeGraphicsNode.java:132)

            at org.apache.batik.gvt.AbstractGraphicsNode.paint(AbstractGraphicsNode.java:415)

            at org.apache.batik.gvt.CompositeGraphicsNode.primitivePaint(CompositeGraphicsNode.java:132)

            at org.apache.batik.gvt.CanvasGraphicsNode.primitivePaint(Unknown Source)

            at org.apache.batik.gvt.AbstractGraphicsNode.paint(AbstractGraphicsNode.java:415)

            at org.apache.batik.gvt.CompositeGraphicsNode.primitivePaint(CompositeGraphicsNode.java:132)

            at org.apache.batik.gvt.AbstractGraphicsNode.paint(AbstractGraphicsNode.java:415)

            at test.SVGList.paint(SVGList.java:72)

            at javax.swing.JComponent.paintChildren(JComponent.java:498)

            at javax.swing.JComponent.paint(JComponent.java:696)

 

The code I used to build the GraphicsNode is like this:

 

        UsrAgent userAgent = new UserAgentAdapter();

        BridgeContext ctx = new BridgeContext(userAgent);

        DocumentLoader docLoader = new DocumentLoader(userAgent);

        GVTBuilder gvtBuilder = new GVTBuilder();       

        SVGDocument svgDocument = null;

        try {

            svgDocument = (SVGDocument) docLoader.loadDocument(uri);

        }

        catch(IOException e) {

            e.printStackTrace();

        }

        GraphicsNode node = gvtBuilder.build(ctx, svgDocument);

 

Node.paint(g2) is in a JComponent.paint(Graphics g). (class test.SVGList).

 

I tried to catch the exception, and got part of the image. This result is by using batik version 1.1.1, and jdk1.3.1. JDK1.4.0 can give me a very low quality image and no exception is thrown.

 

The above code works with other examples, e.g., anne.svg and moonPhases.svg.

 

Thanks in advance.

 

-Guanming    

 

-----Original Message-----
From: Philippe Converset [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, October 08, 2002 4:08 AM
To: Batik Users
Subject: Re: Change fill color in a GraphicsNode

 

Hi,

If your GraphicsNode is a ShapeNode, then you can use the setShapePainter() method.

Here is an example:

      FillShapePainter painter;

      painter = new FillShapePainter(shapeNode.getShape());
      painter.setPaint(Color.RED);
      shapeNode.setShapePainter(painter);
      shapeNode.paint(g2d);

If you want to specify the stroke paint, then you can use StrokeShapePainter and if you want to specify the stroke and the fill paint at the same time, then you must use a CompositeShapePainter on which you add the two previous painters through the addShapePainter() method.

Hope this helps.

Philippe

Guanming Wu a écrit:

Hi,

 

I am new to batik-1.1.1. In one of my applications, I want to paint a GraphicsNode with different colors at different places in a JPanel. In my application, I cannot directly use JSVGComponent or JSVGCanvas, so I embed a SVG in my graphics context by painting a GraphicsNode directly on Graphics2D (Method: Graphics2D.paint(Graphics2D)).

 

I just want if there is a way to set fill color after GraphicsNode is built from SVG document.

 

Thanks,

 

Guanming

 

Reply via email to