Results 1 to 2 of 2
- 01-24-2013, 09:39 AM #1
Member
- Join Date
- Jan 2013
- Location
- Copenhagen
- Posts
- 1
- Rep Power
- 0
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?
- 01-28-2013, 03:36 PM #2
Re: Can't find a method to render existing SVG image by Java Salamande0r in Eclipse
Why do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Image Render Speed
By zirbinator in forum Java 2DReplies: 2Last Post: 08-27-2011, 11:44 PM -
How do I make Eclipse find the main method automatically
By roise_r in forum EclipseReplies: 0Last Post: 06-13-2011, 09:16 PM -
Java Applet loading image; render as you get image?
By ea25 in forum New To JavaReplies: 12Last Post: 04-14-2011, 01:58 PM -
java method injection in existing code
By abanmitra in forum Advanced JavaReplies: 6Last Post: 04-30-2010, 12:02 PM -
Eclipse can't find my image file when generating HTML
By Mateo1041 in forum EclipseReplies: 4Last Post: 01-08-2009, 10:26 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks