Convert Figma logo to code with AI

mono logoSkiaSharp

SkiaSharp is a cross-platform 2D graphics API for .NET platforms based on Google's Skia Graphics Library. It provides a comprehensive 2D API that can be used across mobile, server and desktop models to render images.

4,804
564
4,804
636

Top Related Projects

9,783

Skia is a complete 2D graphic library for drawing Text, Geometries, and Images.

1,844

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.

Quick Overview

SkiaSharp is a cross-platform 2D graphics API for .NET platforms based on Google's Skia graphics library. It provides a powerful, flexible, and efficient way to draw 2D graphics, text, and images across various .NET platforms, including mobile, desktop, and web applications.

Pros

  • Cross-platform compatibility (iOS, Android, Windows, macOS, Linux, etc.)
  • High-performance graphics rendering
  • Extensive API with support for complex drawing operations
  • Active development and community support

Cons

  • Steeper learning curve compared to simpler drawing libraries
  • Large binary size, which may impact app size on mobile platforms
  • Limited 3D capabilities (primarily focused on 2D graphics)
  • Some platform-specific features may require additional setup or workarounds

Code Examples

  1. Drawing a simple shape:
using SkiaSharp;

using (var surface = SKSurface.Create(new SKImageInfo(300, 300)))
{
    var canvas = surface.Canvas;
    canvas.Clear(SKColors.White);

    using (var paint = new SKPaint { Color = SKColors.Blue })
    {
        canvas.DrawCircle(150, 150, 100, paint);
    }

    // Save the surface as a PNG image
    using (var image = surface.Snapshot())
    using (var data = image.Encode(SKEncodedImageFormat.Png, 100))
    using (var stream = File.OpenWrite("output.png"))
    {
        data.SaveTo(stream);
    }
}
  1. Drawing text with a custom font:
using SkiaSharp;

using (var typeface = SKTypeface.FromFile("path/to/custom-font.ttf"))
using (var paint = new SKPaint
{
    Typeface = typeface,
    TextSize = 36,
    Color = SKColors.Black,
    IsAntialias = true
})
{
    canvas.DrawText("Hello, SkiaSharp!", 50, 100, paint);
}
  1. Applying a gradient to a path:
using SkiaSharp;

var path = new SKPath();
path.MoveTo(50, 50);
path.LineTo(250, 50);
path.LineTo(150, 250);
path.Close();

using (var paint = new SKPaint
{
    Style = SKPaintStyle.Fill,
    Shader = SKShader.CreateLinearGradient(
        new SKPoint(50, 50),
        new SKPoint(250, 250),
        new[] { SKColors.Red, SKColors.Blue },
        null,
        SKShaderTileMode.Clamp)
})
{
    canvas.DrawPath(path, paint);
}

Getting Started

  1. Install the SkiaSharp NuGet package in your project:

    dotnet add package SkiaSharp
    
  2. Add the following using statement to your C# file:

    using SkiaSharp;
    
  3. Create an SKSurface to draw on:

    using (var surface = SKSurface.Create(new SKImageInfo(300, 300)))
    {
        var canvas = surface.Canvas;
        // Perform drawing operations on the canvas
    }
    
  4. Use the various drawing methods provided by the SKCanvas class to create your graphics.

Competitor Comparisons

9,783

Skia is a complete 2D graphic library for drawing Text, Geometries, and Images.

Pros of Skia

  • More comprehensive and lower-level graphics API
  • Directly maintained by Google, ensuring up-to-date features and optimizations
  • Supports a wider range of platforms and rendering backends

Cons of Skia

  • Steeper learning curve due to its lower-level nature
  • Requires more setup and configuration for different platforms
  • Larger codebase and potentially higher resource usage

Code Comparison

SkiaSharp:

using SkiaSharp;

using (var surface = SKSurface.Create(width, height, SKColorType.Rgba8888, SKAlphaType.Premul))
{
    var canvas = surface.Canvas;
    canvas.DrawCircle(100, 100, 50, new SKPaint { Color = SKColors.Blue });
}

Skia:

#include "include/core/SkCanvas.h"
#include "include/core/SkSurface.h"

auto surface = SkSurface::MakeRasterN32Premul(width, height);
auto canvas = surface->getCanvas();
SkPaint paint;
paint.setColor(SK_ColorBLUE);
canvas->drawCircle(100, 100, 50, paint);

Both libraries offer powerful graphics capabilities, but SkiaSharp provides a more accessible C# wrapper around Skia's functionality, making it easier to use in .NET environments. Skia, being the core library, offers more fine-grained control and performance optimizations at the cost of increased complexity.

1,844

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.

Pros of Win2D

  • Native Windows integration: Optimized for Windows platforms, providing better performance and seamless integration with Windows APIs
  • DirectX-based: Leverages DirectX for hardware-accelerated 2D and 3D graphics rendering
  • Extensive documentation: Microsoft provides comprehensive documentation and examples for Win2D

Cons of Win2D

  • Limited cross-platform support: Primarily designed for Windows, lacking support for other operating systems
  • Steeper learning curve: Requires familiarity with DirectX concepts and Windows-specific development

Code Comparison

Win2D:

using Microsoft.Graphics.Canvas;
using Windows.UI;

CanvasDevice device = CanvasDevice.GetSharedDevice();
CanvasRenderTarget renderTarget = new CanvasRenderTarget(device, width, height, 96);

using (CanvasDrawingSession ds = renderTarget.CreateDrawingSession())
{
    ds.Clear(Colors.White);
    ds.DrawEllipse(100, 100, 50, 50, Colors.Blue);
}

SkiaSharp:

using SkiaSharp;

SKBitmap bitmap = new SKBitmap(width, height);
using (SKCanvas canvas = new SKCanvas(bitmap))
{
    canvas.Clear(SKColors.White);
    canvas.DrawCircle(100, 100, 50, new SKPaint { Color = SKColors.Blue });
}

Both libraries offer similar functionality for 2D graphics rendering, but Win2D is more focused on Windows development, while SkiaSharp provides cross-platform support.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

SkiaSharp

SkiaSharp HarfBuzzSharp

SkiaSharp.Views SkiaSharp.Views.Maui.Controls SkiaSharp.Views.Uno

discord SkiaSharp API Docs HarfBuzzSharp API Docs SkiaSharp Guides

Build Status Build Status

SkiaSharp is a cross-platform 2D graphics API for .NET platforms based on Google's Skia Graphics Library (skia.org). It provides a comprehensive 2D API that can be used across mobile, server and desktop models to render images.

SkiaSharp provides cross-platform bindings for:

  • .NET Standard 1.3
  • .NET Core
  • .NET 6
  • Tizen
  • Android
  • iOS
  • tvOS
  • macOS
  • Mac Catalyst
  • WinUI 3 (Windows App SDK / Uno Platform)
  • Windows Classic Desktop (Windows.Forms / WPF)
  • Web Assembly (WASM)
  • Uno Platform (iOS / macOS / Android / WebAssembly)

The API Documentation is available on the web to browse.

Using SkiaSharp

SkiaSharp is available as a convenient NuGet package, to use install the package like this:

nuget install SkiaSharp

Because there are multiple distros of Linux, and we cannot possibly support them all, we have a separate NuGet package that will contain the supported binaries for a few distros: SkiaSharp.NativeAssets.Linux. (distros) (more info)

There is also a early access feed that you can use to get the latest and greatest, before it goes out to the public:

https://aka.ms/skiasharp-eap/index.json

Building SkiaSharp

Building SkiaSharp is mostly straight forward. The main issue is the multiple dependencies for each platform.

However, these are easy to install as they are found on the various websites. If you are just working on managed code, it is even easier as there mays to skip all the native builds.

  • To get started building, go here.
  • If you are just wanting a custom Linux build, go here

Contributors

Made with contrib.rocks.

Compare Code

Here are some links to show the differences in our code as compared to Google's code.

What version are we on? m118
Are we up-to-date with Google? Compare
What have we added? Compare