Click here to Skip to main content
15,302,501 members
Articles / Programming Languages / C#
Posted 8 Mar 2003


85 bookmarked

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

Rate me:
Please Sign up or sign in to vote.
4.70/5 (28 votes)
8 Mar 20032 min read
Svg.Net is a C# framework for creating SVG images. A GDI-SVG bridge is implemented on top of it.

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.


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.


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
Web Developer
United Kingdom United Kingdom
My interests are software engineering, Japanese, and talking about how good things used to be back in the good old days.

Favorite Toy:

Comments and Discussions

BugNot fully working SVG Pin
The-Day20-Nov-20 3:57
MemberThe-Day20-Nov-20 3:57 
QuestionAxSVGACTIVEXLib not found Pin
Member 1411709330-Jan-19 18:22
MemberMember 1411709330-Jan-19 18:22 
QuestionThe Help file doesn't work in Windows 10 it seems. Am I right? Pin
Stef Cas9-Jun-18 5:14
MemberStef Cas9-Jun-18 5:14 
AnswerRe: The Help file doesn't work in Windows 10 it seems. Am I right? Pin
JohnHolliday8-Nov-18 4:38
MemberJohnHolliday8-Nov-18 4:38 
QuestionEquivalent of Graphics.FromImage ? Pin
toan69nguyen@gmail.com12-Feb-18 22:09
Membertoan69nguyen@gmail.com12-Feb-18 22:09 
Questionhomepage here Pin
DamianDixon22-Oct-14 23:14
MemberDamianDixon22-Oct-14 23:14 
QuestionProject homepage not accessible Pin
Brian Herbert6-Dec-13 1:27
MemberBrian Herbert6-Dec-13 1:27 
BugIncompatible with some locale Pin
lill.LEIF2-Jun-12 22:30
Memberlill.LEIF2-Jun-12 22:30 
GeneralAcessViolationException setting the SRC property Pin
James Darlington27-Oct-10 11:44
MemberJames Darlington27-Oct-10 11:44 
GeneralPlease provide the sample code... to deal with the file having dynamic element entries.. using XmlAttributeCollection...using C# Pin
Nikkiee25-Jun-09 12:04
MemberNikkiee25-Jun-09 12:04 
Generalremove and insert the another attribute Pin
Nikkiee20-Jun-09 12:53
MemberNikkiee20-Jun-09 12:53 
GeneralStack Overflow on complex pages Pin
Franz Fiala12-Apr-09 20:45
MemberFranz Fiala12-Apr-09 20:45 
GeneralIncompatible output, not standard svg Pin
valeriob24-Nov-08 1:24
Membervaleriob24-Nov-08 1:24 
QuestionAnybody can put an example to read a SVG file with this library? Pin
Marcosjgr12-Sep-08 7:47
MemberMarcosjgr12-Sep-08 7:47 
AnswerRe: Anybody can put an example to read a SVG file with this library? Pin
Nikkiee10-Jun-09 15:16
MemberNikkiee10-Jun-09 15:16 
GeneralRe: Anybody can put an example to read a SVG file with this library? Pin
Nikkiee10-Jun-09 15:19
MemberNikkiee10-Jun-09 15:19 
AnswerRe: Anybody can put an example to read a SVG file with this library? Pin
Marcosjgr15-Jun-09 7:34
MemberMarcosjgr15-Jun-09 7:34 
GeneralRe: Anybody can put an example to read a SVG file with this library? Pin
Nikkiee20-Jun-09 12:47
MemberNikkiee20-Jun-09 12:47 
GeneralWarnings and Excepetions, please Help. Pin
Marcosjgr8-Sep-08 15:30
MemberMarcosjgr8-Sep-08 15:30 
GeneralRe: Warnings and Excepetions, please Help. Pin
Marcosjgr12-Sep-08 7:38
MemberMarcosjgr12-Sep-08 7:38 
QuestionSvgAElement Pin
aliov_857-Nov-07 0:04
Memberaliov_857-Nov-07 0:04 
AnswerRe: SvgAElement Pin
aliov_8519-Nov-07 5:44
Memberaliov_8519-Nov-07 5:44 2.0 and SVGNet _VERY URGENT_PLEASE Pin
aliov_8516-Oct-07 22:23
Memberaliov_8516-Oct-07 22:23 
AnswerRe: 2.0 and SVGNet _VERY URGENT_PLEASE Pin
aliov_8519-Nov-07 5:39
Memberaliov_8519-Nov-07 5:39 
Generalerror in svgCtl.SRC = "c:\\temp\\foo.svg" Pin
Razik3-Apr-07 22:37
MemberRazik3-Apr-07 22:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.