Popularity
6.0
Stable
Activity
0.2
-
642
47
131

Code Quality Rank: L3
Programming language: C#
License: MIT License
Tags: iOS     Android     Pcl     Mac     Graphics     Vector     Drawing     Xamarin     Imaging     Draw     Image     Svg     Png     Render    
Latest version: v0.5.0

NGraphics alternatives and similar packages

Based on the "Graphics" category.
Alternatively, view NGraphics alternatives based on common mentions on social networks and blogs.

  • Live-Charts

    Animated, MVVM friendly .Net charts, for WPF, WinForms under the MIT Licence (Free), written in C#, LiveCharts listens for any change in your data automatically and updates UI. http://lvcharts.net/
  • Oxyplot

    OxyPlot is a cross-platform plotting library for .NET
  • Scout APM uses tracing logic that ties bottlenecks to source code so you know the exact line of code causing performance issues and can get back to building a great product faster.
    Sponsored scoutapm.com
  • OpenTK

    The Open Toolkit is an advanced, low-level C# library that wraps OpenGL, OpenCL and OpenAL
  • Win2D

    Win2D is an easy-to-use Windows Runtime API for immediate mode 2D graphics rendering with GPU acceleration. It is available to C#, C++ and VB developers writing apps for the Windows Universal Platform (UWP). It utilizes the power of Direct2D, and integrates seamlessly with XAML and CoreWindow.
  • Helix Toolkit

    Helix Toolkit is a collection of 3D components for .NET
  • Veldrid

    A low-level, portable graphics and compute library for .NET
  • Interactive Data Display for WPF

    Interactive Data Display for WPF is a set of controls for adding interactive visualization of dynamic data to your application.
  • LibVLCSharp

    LibVLCSharp is a cross-platform audio and video API for .NET platforms based on VideoLAN's LibVLC Library.
  • ScottPlot

    Interactive Plotting Library for .NET
  • Silk.NET

    A cross-platform, high-performance, low-level .NET Standard wrapper for many advanced APIs such as OpenGL, OpenCL, OpenAL, OpenXR, Assimp, GLFW, as well as many others. In addition to wrapping over Native APIs, it also comes with its own Windowing and Input abstraction. This makes game and application development with Silk.NET a breeze, and has pretty much everything a 3D application developer would need.
  • LibTessDotNet

    .NET port of the famous GLU Tessellator, triangulates polygons
  • SciChart

    Examples, tutorials, and sandbox for SciChart WPF: High Performance Realtime Charts
  • RealTimeGraphX

    RealTimeGraphX is a data type agnostic, high performance plotting library for WPF, UWP and soon, Xamarin Forms.
  • AssimpNet

    A cross-platform .NET Standard wrapper for the Open Asset Importer ("Assimp"). The library enables importing, processing, and exporting of 3D models for rendering in graphics/game applications. Over 40 formats are supported for importing (e.g. OBJ, FBX, GLTF, 3DS, Collada) and a subset of those formats can be exported to (e.g. OBJ, GLTF, 3DS, Collada). Mesh processing features allow for mesh data to be generated or optimized for real-time rendering.

Do you think we are missing an alternative of NGraphics or a related project?

Add another 'Graphics' Package

README

NGraphics

NuGet Package Build

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.

Installation

Install NGraphics from nuget.

Getting Started

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"));

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.

Pens and Brushes

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"));

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.

Colors

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).

Retained Mode

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);

Platforms

  • Android (Xamarin) using Android.Graphics
    • CanvasCanvas wraps a Android.Graphics.Canvas
  • iOS (Xamarin) using CoreGraphics
    • CGContextCanvas wraps a CoreGraphics.CGContext
  • Mac (Xamarin) using CoreGraphics
    • CGContextCanvas wraps a CoreGraphics.CGContext
  • .NET 4.5 using System.Drawing
    • GraphicsCanvas wraps a System.Drawing.Graphics
  • Windows Store 8.1 using Direct2D
    • RenderTargetCanvas wraps a SharpDX.Direct2D1.RenderTarget
  • Windows Phone 8.1 using Direct2D
    • RenderTargetCanvas wraps a SharpDX.Direct2D1.RenderTarget
  • Universal Windows Platform (UWP) using Direct2D
    • RenderTargetCanvas wraps a SharpDX.Direct2D1.RenderTarget

Editor

To 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.

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.

Examples

For more examples, check out the images in the TestResults directory and the test code that generated them.

Icon

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"));

Cats

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"));

License

The MIT License (MIT)

See [LICENSE](LICENSE) for details.


*Note that all licence references and agreements mentioned in the NGraphics README section above are relevant to that project's source code only.