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 "K, Balamurugan (CORP, GEITC)" <Ba...@geind.ge.com> on 2002/03/28 13:03:51 UTC

Memory problem

Hi,
	I am reading the svg file using renderer ( i tried both static,
dynamic) and getting the offscreen image (Buffered image). Following is the
code which does that. 



public class SVGToImage
{

    StaticRenderer renderer;
    UserAgent      userAgent;
    DocumentLoader loader;
    BridgeContext  ctx;
    BufferedImage image;
    BufferedImage display;
    File svgFile;
    Dimension size;

    SVGToImage(File svgFile, Dimension size)
    {
      this.svgFile = svgFile;
      if(size == null)
       size = Toolkit.getDefaultToolkit().getScreenSize();
      else
      	this.size = size;
      renderer = new StaticRenderer();
      //renderer = new DynamicRenderer();
      userAgent = new UserAgentAdapter();
      loader    = new DocumentLoader(userAgent);
      ctx       = new BridgeContext(userAgent, loader);
      display = new BufferedImage(size.width, size.height,
                                    BufferedImage.TYPE_INT_BGR);
      buildImage();
    }

    public BufferedImage buildImage()
    {
        renderer.setDoubleBuffered(true);
        GraphicsNode   gvtRoot = null;
		GVTBuilder builder = new GVTBuilder();
		try
		{
			//System.out.println("Reading: " + svgFile);
	    	Document svgDoc =
loader.loadDocument(svgFile.toURL().toString());
	        //System.out.println("Building: " + svgFile);
	        gvtRoot = builder.build(ctx, svgDoc);
	        //System.out.println("Rendering: " + svgFile);
            renderer.setTree(gvtRoot);
            Element elt = ((SVGDocument)svgDoc).getRootElement();
			//System.out.println("display" + display);
			renderer.setTransform(ViewBox.getViewTransform
		            (null, elt, display.getWidth(),
display.getHeight()));
	
renderer.updateOffScreen(display.getWidth(),display.getHeight());
			Rectangle r = new Rectangle(0,
0,display.getWidth(),display.getHeight());
			renderer.repaint(r);
            image = renderer.getOffScreen();
            //System.out.println("Painting: " + image);
            //Graphics2D g2d = display.createGraphics();
			//g2d.setColor(new Color(0,0,0));
			//g2d.drawImage(image, null, 0, 0);
            return image;

      }catch(Exception e)
       {
			  e.printStackTrace();
			  return null;
		}

  }


   public static void main(String arg[])
   {

            try
            {
			   File f = new File("Tri.svg");
               new SVGToImage(f,null);
		    }catch(Exception e)
		     {
				 e.printStackTrace();
			 }

   }

}

It takes i have to display these buffere images for icons. When i do this if
i have more icons it eats memory and gives me memory out of stack exception.
Can anybody through some light on this problem. 

Thanks 
Bala






"THIS E-MAIL MESSAGE ALONG WITH ANY ATTACHMENTS IS INTENDED ONLY FOR THE
ADDRESSEE and may contain confidential and privileged information.
If the reader of this message is not the intended recipient,
you are notified that any dissemination, distribution or copy of this 
communication is strictly Prohibited. 
If you have received this message by error, please notify us 
immediately, return the original mail to the sender and delete the 
message from your system."


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