5,691,626 members and growing! (14,078 online)
Email Password   helpLost your password?
Languages » C# » General     Intermediate

An SVG framework in C# and an SVG-GDI+ bridge

By Ben Peterson

Svg.Net is a C# framework for creating SVG images. A GDI-SVG bridge is implemented on top of it.
C#, Windows, .NET 1.0, .NETVisual Studio, VS.NET2002, Dev

Posted: 8 Mar 2003
Updated: 8 Mar 2003
Views: 112,903
Bookmarked: 36 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
23 votes for this Article.
Popularity: 6.06 Rating: 4.45 out of 5
1 vote, 4.3%
1
0 votes, 0.0%
2
1 vote, 4.3%
3
7 votes, 30.4%
4
14 votes, 60.9%
5

SvgNet & SvgGdi

SvgNet is a C# library designed to facilitate the processing and particularly the creation of SVG documents in C#.
The project homepage is here. Source on the homepage may be more recent than The Code Project copy.

What it does

SvgNet consists of the following parts:

Classes to represent SVG elements and SVG types

SvgNet contains a family of classes that represent SVG elements (e.g. ellipse or tspan) and SVG types (e.g. a transformation list, a style, or a path description). The SVG types are provided with operators to make constructing and modifying SVG documents easy. For example, to change some properties of a style you can do:
myEllipse.Style = new Style("fill:red");
myEllipse.Style.Set("opacity", 0.5);
myEllipse.Style += "stroke:black";
        

Classes to read, write and copy SVG scenes

To get an SVG string from a tree of SVG elements you have created is as simple as this:
SvgElement myRootElement = SvgFactory.ReadSvgString(s);
s = myRootElement.WriteSvgString(); 
XML output can use entities to reduce the size and increase the legibility of the document.

The SvgFactory class also contains methods to make a deep copy of any SVG node and its descendants. All SVG types and elements are cloneable.

The Svg-Gdi bridge

The SvgGdi bridge is a set of classes that use SvgNet to translate between SVG and GDI+. What this means is that any code that uses GDI+ to draw graphics can easily output SVG as well, simply by plugging in the SvgGraphics object. This object is exactly the same as a regular .NET Graphics object, but creates an SVG tree. Even things like hatched fills and line anchors are implemented. The irritatingly old-fashioned 'current transformation' system of GDI+ is implemented by creating nested SVG group elements, resulting in SVG output that's a bit cleaner than the corresponding GDI+ metafile in some ways.

SvgGdi is the main use for SvgNet, although other things (a collection of basic shapes, maybe charting tools) may be built on SvgNet in the future.

Documentation

The SvgNet class libraries are documented in this help package. Additionally, there are two example applications bundled with SvgNet:
  • SvgDocTest -- test application that reads and writes documents and constructs an SVG document. This application is both an example and test system.
  • SvgGdiTest -- application that draws various scenes with SVG and GDI+. It is both an example of SvgGdi use, and a test of how accurate SvgGdi's emulation of GDI+ is.

The SvgNet Project

SvgNet is an Open Source project under a BSD-like license (license terms are reproduced in every SvgNet source file). SvgNet is copyright 2003 RiskCare Ltd.

The SvgNet project home page is here.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Ben Peterson


My interests are software engineering, Japanese, and talking about how good things used to be back in the good old days.

URL: http://www.jbrowse.com
Favorite Toy: http://www.ruby-lang.org


Occupation: Web Developer
Location: United Kingdom United Kingdom

Other popular C# articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 40 (Total in Forum: 40) (Refresh)FirstPrevNext
GeneralIncompatible output, not standard svgmembervaleriob2:24 24 Nov '08  
GeneralAnybody can put an example to read a SVG file with this library?memberMarcosjgr8:47 12 Sep '08  
GeneralWarnings and Excepetions, please Help.memberMarcosjgr16:30 8 Sep '08  
GeneralRe: Warnings and Excepetions, please Help.memberMarcosjgr8:38 12 Sep '08  
QuestionSvgAElementmemberaliov_851:04 7 Nov '07  
AnswerRe: SvgAElementmemberaliov_856:44 19 Nov '07  
QuestionAsp.net 2.0 and SVGNet _VERY URGENT_PLEASEmemberaliov_8523:23 16 Oct '07  
AnswerRe: Asp.net 2.0 and SVGNet _VERY URGENT_PLEASEmemberaliov_856:39 19 Nov '07  
Generalerror in svgCtl.SRC = "c:\\temp\\foo.svg"memberRazik23:37 3 Apr '07  
GeneralNew Home Page Locationmemberlogan133716:29 3 Mar '07  
GeneralRe: New Home Page Locationmemberalreadyused10:52 5 Aug '08  
GeneralGoodmembernorm .net2:10 28 Feb '07  
QuestionStill alive?memberRazputin7:17 5 Feb '07  
AnswerRe: Still alive?memberBen Peterson7:25 5 Feb '07  
GeneralRe: Still alive?memberapper1:55 28 Sep '08  
Generali don't know how to install the source file...:(memberhenin1:33 18 Oct '06  
GeneralASP.NET + SvgNet??memberMicke1233:41 16 Oct '06  
QuestionCompiler Errorsmember.:MaryAnne:.19:33 22 Aug '06  
AnswerRe: Compiler ErrorsmemberBen Peterson0:27 23 Aug '06  
Questionplease help me!membertzgpxl23:55 23 Jul '06  
AnswerRe: please help me!membermengxh200022:40 16 Aug '06  
GeneralSvg in SVGsussAnonymous1:27 12 Aug '04  
GeneralRe: Svg in SVGmemberaaaaaaaaaaaaaaaasa19:11 16 Aug '04  
GeneralRe: Svg in SVGmemberBen Peterson23:53 16 Aug '04  
GeneralRe: Svg in SVGmemberaaaaaaaaaaaaaaaaasa0:48 17 Aug '04  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 8 Mar 2003
Editor: Chris Maunder
Copyright 2003 by Ben Peterson
Everything else Copyright © CodeProject, 1999-2008
Web17 | Advertise on the Code Project