Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2013
    Location
    Copenhagen
    Posts
    1
    Rep Power
    0

    Default Can't find a method to render existing SVG image by Java Salamande0r in Eclipse

    -2 down vote favorite


    In the following link an SVG image is created by code before getting rendered. At Dynamic SVGIcon demo — Java.net this compiles flawless:

    class IconPanel extends JPanel { public static final long serialVersionUID = 0;

    final SVGIcon icon;


    public IconPanel()
    {
    StringReader reader = new StringReader(makeDynamicSVG());
    URI uri = SVGCache.getSVGUniverse().loadSVG(reader, "myImage");
    icon = new SVGIcon();
    icon.setSvgURI(uri);

    setPreferredSize(new Dimension(400, 400));
    }

    public void paintComponent(Graphics g)
    {
    final int width = getWidth();
    final int height = getHeight();

    g.setColor(getBackground());
    g.fillRect(0, 0, width, height);

    icon.paintIcon(this, g, 0, 0);
    }

    private String makeDynamicSVG()
    {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);

    pw.println("<svg width=\"400\" height=\"400\" style=\"fill:none;stroke-width:4\">");
    pw.println(" <circle cx=\"200\" cy=\"200\" r=\"200\" style=\"stroke:blue\"/>");
    pw.println(" <circle cx=\"140\" cy=\"140\" r=\"40\" style=\"stroke:red\"/>");
    pw.println(" <circle cx=\"260\" cy=\"140\" r=\"40\" style=\"stroke:red\"/>");
    pw.println(" <polyline points=\"100 300 150 340 250 240 300 300\" style=\"stroke:red\"/>");
    pw.println("</svg>");

    pw.close();
    return sw.toString();
    }

    }

    But I want to render an SVG image that is not being created on the fly. An SVG Image I have already made on beforehand. So instead of referring to "myImage" (as in above) I want to do something like this:

    class IconPanel extends JPanel { public static final long serialVersionUID = 0;

    final SVGIcon icon;


    public IconPanel()
    {

    SVGUniverse svgUni = new SVGUniverse();
    StringReader reader = new StringReader(null);
    URI pw = svgUni.loadSVG(reader, "C:/Users/TD_DS_IS/workspaceJuno/svgSalamander/res/SVG_til_Tattoo.svg");
    icon = new SVGIcon();
    icon.setSvgURI(pw);

    setPreferredSize(new Dimension(400, 400));
    }

    public void paintComponent(Graphics g)
    {
    final int width = getWidth();
    final int height = getHeight();

    g.setColor(getBackground());
    g.fillRect(0, 0, width, height);

    icon.paintIcon(this, g, 0, 0);
    }

    private String makeDynamicSVG()
    {
    SVGUniverse svgUni = new SVGUniverse();
    StringReader reader = new StringReader(null);
    URI pw = svgUni.loadSVG(reader, "/svgSalamander/res/SVG_til_Tattoo.svg");
    return pw.toString();
    }

    }

    I want to render my own premade SVG - so which methods under SVGUniverse (or just universe as the link claims) can be used to do this?

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: Can't find a method to render existing SVG image by Java Salamande0r in Eclipse

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Image Render Speed
    By zirbinator in forum Java 2D
    Replies: 2
    Last Post: 08-28-2011, 12:44 AM
  2. Replies: 0
    Last Post: 06-13-2011, 10:16 PM
  3. Replies: 12
    Last Post: 04-14-2011, 02:58 PM
  4. java method injection in existing code
    By abanmitra in forum Advanced Java
    Replies: 6
    Last Post: 04-30-2010, 01:02 PM
  5. Replies: 4
    Last Post: 01-08-2009, 11:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •