![]() |
VOOZH | about |
dotnet add package NGraphics --version 0.9.24
NuGet\Install-Package NGraphics -Version 0.9.24
<PackageReference Include="NGraphics" Version="0.9.24" />
<PackageVersion Include="NGraphics" Version="0.9.24" />Directory.Packages.props
<PackageReference Include="NGraphics" />Project file
paket add NGraphics --version 0.9.24
#r "nuget: NGraphics, 0.9.24"
#:package NGraphics@0.9.24
#addin nuget:?package=NGraphics&version=0.9.24Install as a Cake Addin
#tool nuget:?package=NGraphics&version=0.9.24Install as a Cake Tool
<img src="TestResults/Icon-Mac.png" width="64" height="64" />
NGraphics is a cross platform library for rendering vector graphics on .NET. It provides a unified API for both immediate and retained mode graphics using high quality native renderers.
You can use it for cross platform rendering of UI widgets. Or as the basis for graphically rich interactive views. Or maybe you just want an easy way to import and export SVG and PNG files. Either way, I'm sure you'll find something interesting here.
The most important class is ICanvas. Uses canvases to render vector graphics (rectangles, ellipses, paths) to "something". Sometimes canvases are views on the screen, sometimes they are images -- you never really know.
We can draw a little house easily enough:
var canvas = Platforms.Current.CreateImageCanvas (new Size (100), scale: 2);
var skyBrush = new LinearGradientBrush (Point.Zero, Point.OneY, Colors.Blue, Colors.White);
canvas.FillRectangle (new Rect (canvas.Size), skyBrush);
canvas.FillEllipse (10, 10, 30, 30, Colors.Yellow);
canvas.FillRectangle (50, 60, 60, 40, Colors.LightGray);
canvas.FillPath (new PathOp[] {
new MoveTo (40, 60),
new LineTo (120, 60),
new LineTo (80, 30),
new ClosePath ()
}, Colors.Gray);
canvas.GetImage ().SaveAsPng (GetPath ("Example1.png"));
<img src="TestResults/Example1-Mac.png" width="100" height="100" />
Platforms.Current.CreateImageCanvas is just our tricky way to get a platform-specific ICanvas that we can rendered on. IImageCanvases are special because you can call GetImage to get an image of the drawing when you are done. We use a scale of 2 to render retina graphics and keep this README looking good.
Paths are drawn using standard turtle graphics.
When drawing, you have a choice of pens to stroke the object with or brushes to fill it with.
Anyway.
Pens can be any color and any width.
var canvas = Platforms.Current.CreateImageCanvas (new Size (120*5, 120), scale: 2);
canvas.Translate (20, 20);
for (var i = 0; i < 5; i++) {
canvas.DrawEllipse (
new Rect (new Size (80)),
pen: Pens.DarkGray.WithWidth (1 << i),
brush: Brushes.LightGray);
canvas.Translate (120, 0);
}
canvas.GetImage ().SaveAsPng (GetPath ("PenWidths.png"));
<img src="TestResults/PenWidths-Mac.png" width="600" height="120" />
Brushes can be solid colors or trippy multi-color gradients (linear and radial!)
There is no multi-layering within elements, so you will have to draw them a few times with different brushes to get complex effects.
What would a graphics library be without a Color class? Well, this one is a struct. Colors are light-weight, have fun with them.
Normally you will use the RGBA constructor of color: new Color (r, g, b, a) where each value can range from 0 to 1.
If you're not normal, you might prefer the web notation: Color.FromRGB (0xBEEFEE).
Sometimes it's nice to hang onto the graphical elements themselves so that you can change them later, or perhaps cache them from an expensive-to-compute draw operation, or maybe you just want to sing to them. Whatever your needs, NGraphics exposes the following graphical elements:
Rectangles are best used for drawing rectangles.Ellipses can also be used to draw ovals and circles.Paths can draw anything that you can imagine, and more. Lines, curves, turtles, they're all for the taking.var circle = new Ellipse (new Rectangle (Point.Zero, new Size (10)));
ICanvas canvas = ...;
circle.Draw (canvas);
CanvasCanvas wraps a Android.Graphics.CanvasCGContextCanvas wraps a CoreGraphics.CGContextCGContextCanvas wraps a CoreGraphics.CGContextGraphicsCanvas wraps a System.Drawing.GraphicsRenderTargetCanvas wraps a SharpDX.Direct2D1.RenderTargetRenderTargetCanvas wraps a SharpDX.Direct2D1.RenderTargetRenderTargetCanvas wraps a SharpDX.Direct2D1.RenderTargetTo speed up the process of drawing with code, NGraphics ships with a code editor and live preview for OS X. Download the editor from the Releases page.
<img src="Documentation/Editor.png" width="640" />
Any C# file that can be independently compiled can be used. The advantage of this editor over Xamarin Studio is that you can work on your drawings without having to wait for your whole project to compile and run.
Simply compile and run the project NGraphics.Editor or download the editor to get started.
For more examples, check out the images in the TestResults directory and the test code that generated them.
The NGraphics icon can be rendered using a simple repeating path:
var size = new Size (64);
var canvas = Platforms.Current.CreateImageCanvas (size, scale: 2);
canvas.SaveState ();
canvas.Scale (size);
canvas.Translate (1 / 8.0, 0);
var p = new Path ();
p.MoveTo (0, 1);
p.LineTo (0, 0);
p.LineTo (0.5, 1);
p.LineTo (0.5, 0);
var colors = new [] {
"#DCDCDD",
"#C5C3C6",
"#46494C",
"#4C5C68",
"#68A5E2",
};
foreach (var c in colors) {
p.Pen = new Pen (c, 1 / 4.0);
p.Draw (canvas);
canvas.Translate (1 / 16.0, 0);
}
canvas.GetImage ().SaveAsPng (GetPath ("Icon.png"));
<img src="TestResults/Icon-Mac.png" width="64" height="64" />
NGraphics also supports scaling cats:
var img = GetResourceImage ("cat.png");
var canvas = Platform.CreateImageCanvas (new Size (100, 200), transparency: true);
canvas.DrawImage (img, new Rect (new Size (50)));
canvas.DrawImage (img, new Rect (new Point (50, 0), new Size (50)));
canvas.DrawImage (img, new Rect (new Point (0, 50), new Size (50, 150)));
canvas.DrawImage (img, new Rect (new Point (50, 50), new Size (50, 150)));
canvas.GetImage ().SaveAsPng (GetPath ("ImageCanvas.Cats"));
<img src="TestResults/ImageCanvas.Cats-Mac.png" width="100" height="200" />
The MIT License (MIT)
See for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-android35.0 net9.0-android35.0 is compatible. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-ios18.0 net9.0-ios18.0 is compatible. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-macos15.0 net9.0-macos15.0 is compatible. net9.0-tvos net9.0-tvos was computed. net9.0-tvos18.0 net9.0-tvos18.0 is compatible. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on NGraphics:
| Package | Downloads |
|---|---|
|
SheshaMobile.Core
Common application functionality and features to be shared across the framework |
|
|
SheshaMobile.Core.Android
Common application functionality and features to be shared across the framework for Android |
|
|
NControl
NControl is a Xamarin.Forms wrapper control built around the NGraphics library enabling developers to create custom controls without the need for custom renderers. |
|
|
NControl.Controls
NControl.Controls is a collection of Xamarin.Forms controls using the NControl library to enable the creation of advanced custom controls in a true cross-platform way. |
|
|
NControl.Mvvm
NControl.Mvvm is a small Mvvm library built to be used with the NControl.Controls library. |
Showing the top 6 popular GitHub repositories that depend on NGraphics:
| Repository | Stars |
|---|---|
|
praeclarum/FuGetGallery
An alternative web UI for browsing nuget packages
|
|
| xamarin/Sport | |
|
muak/AiForms.SettingsView
SettingsView for Xamarin.Forms
|
|
|
chrfalch/NControl
Simple Xamarin.Forms wrapper control around the NGraphics library
|
|
|
Clancey/gMusic
This is a multi platform music player.
|
|
| twintechs/TwinTechsFormsLib |
| Version | Downloads | Last Updated |
|---|---|---|
| 0.9.24 | 38,537 | 4/30/2025 |
| 0.6.0-beta2 | 18,085 | 2/7/2020 |
| 0.6.0-beta1 | 9,314 | 1/27/2019 |
| 0.5.0 | 12,974,421 | 8/24/2018 |
| 0.5.0-beta1 | 3,188 | 7/13/2017 |
| 0.4.0 | 339,327 | 12/30/2015 |
| 0.3.1 | 36,527 | 8/10/2015 |
| 0.3.0 | 32,272 | 8/9/2015 |
| 0.2.2 | 35,546 | 3/31/2015 |
| 0.2.1 | 32,016 | 3/30/2015 |
| 0.1.10 | 32,681 | 3/16/2015 |
| 0.1.9 | 31,955 | 2/7/2015 |
| 0.1.8 | 31,929 | 2/5/2015 |
| 0.1.7 | 31,966 | 2/5/2015 |