Click here to Skip to main content
11,927,711 members (54,482 online)
Click here to Skip to main content
Add your own
alternative version


77 bookmarked

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

, 8 Mar 2003
Rate this:
Please Sign up or sign in to vote.
Svg.Net is a C# framework for creating SVG images. A GDI-SVG bridge is implemented on top of it.
<!-- Add the rest of your HTML here -->

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:

You may also be interested in...

Comments and Discussions

Questionhomepage here Pin
DamianDixon23-Oct-14 0:14
memberDamianDixon23-Oct-14 0:14 
QuestionProject homepage not accessible Pin
Pie and Ale6-Dec-13 2:27
memberPie and Ale6-Dec-13 2:27 
BugIncompatible with some locale Pin
lill.LEIF2-Jun-12 23:30
memberlill.LEIF2-Jun-12 23:30 
GeneralAcessViolationException setting the SRC property Pin
James Darlington27-Oct-10 12:44
memberJames Darlington27-Oct-10 12:44 
GeneralPlease provide the sample code... to deal with the file having dynamic element entries.. using XmlAttributeCollection...using C# Pin
Nikkiee25-Jun-09 13:04
memberNikkiee25-Jun-09 13:04 
Generalremove and insert the another attribute Pin
Nikkiee20-Jun-09 13:53
memberNikkiee20-Jun-09 13:53 
GeneralStack Overflow on complex pages Pin
Franz Fiala12-Apr-09 21:45
memberFranz Fiala12-Apr-09 21:45 
GeneralIncompatible output, not standard svg Pin
valeriob24-Nov-08 2:24
membervaleriob24-Nov-08 2:24 
QuestionAnybody can put an example to read a SVG file with this library? Pin
Marcosjgr12-Sep-08 8:47
memberMarcosjgr12-Sep-08 8:47 
AnswerRe: Anybody can put an example to read a SVG file with this library? Pin
Nikkiee10-Jun-09 16:16
memberNikkiee10-Jun-09 16:16 
GeneralRe: Anybody can put an example to read a SVG file with this library? Pin
Nikkiee10-Jun-09 16:19
memberNikkiee10-Jun-09 16:19 
AnswerRe: Anybody can put an example to read a SVG file with this library? Pin
Marcosjgr15-Jun-09 8:34
memberMarcosjgr15-Jun-09 8:34 
GeneralRe: Anybody can put an example to read a SVG file with this library? Pin
Nikkiee20-Jun-09 13:47
memberNikkiee20-Jun-09 13:47 
GeneralWarnings and Excepetions, please Help. Pin
Marcosjgr8-Sep-08 16:30
memberMarcosjgr8-Sep-08 16:30 
GeneralRe: Warnings and Excepetions, please Help. Pin
Marcosjgr12-Sep-08 8:38
memberMarcosjgr12-Sep-08 8:38 
QuestionSvgAElement Pin
aliov_857-Nov-07 1:04
memberaliov_857-Nov-07 1:04 
AnswerRe: SvgAElement Pin
aliov_8519-Nov-07 6:44
memberaliov_8519-Nov-07 6:44 2.0 and SVGNet _VERY URGENT_PLEASE Pin
aliov_8516-Oct-07 23:23
memberaliov_8516-Oct-07 23:23 
AnswerRe: 2.0 and SVGNet _VERY URGENT_PLEASE Pin
aliov_8519-Nov-07 6:39
memberaliov_8519-Nov-07 6:39 
Generalerror in svgCtl.SRC = "c:\\temp\\foo.svg" Pin
Razik3-Apr-07 23:37
memberRazik3-Apr-07 23:37 
GeneralNew Home Page Location Pin
logan13373-Mar-07 16:29
memberlogan13373-Mar-07 16:29 
GeneralRe: New Home Page Location Pin
alreadyused5-Aug-08 10:52
memberalreadyused5-Aug-08 10:52 
GeneralGood Pin
norm .net28-Feb-07 2:10
membernorm .net28-Feb-07 2:10 
QuestionStill alive? Pin
Razputin5-Feb-07 7:17
memberRazputin5-Feb-07 7:17 
AnswerRe: Still alive? Pin
Ben Peterson5-Feb-07 7:25
memberBen Peterson5-Feb-07 7:25 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.151126.1 | Last Updated 9 Mar 2003
Article Copyright 2003 by Ben Peterson
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid