Resources for visualizing data using C# and the .NET platform
Draw Graphics with SkiaSharp in a C# Console App

This article describes how to draw graphics from a C# console application and save the output as an image file using SkiaSharp.

1. Create a Console App

dotnet new console

2. Add NuGet Packages

dotnet add package SkiaSharp

3. Draw some Graphics

This is the full code for a .NET 6 console app

using SkiaSharp;

// Create an image and fill it blue
SKBitmap bmp = new(640, 480);
using SKCanvas canvas = new(bmp);

// Draw lines with random positions and thicknesses
Random rand = new(0);
SKPaint paint = new() { Color = SKColors.White.WithAlpha(100), IsAntialias = true };
for (int i = 0; i < 100; i++)
    SKPoint pt1 = new(rand.Next(bmp.Width), rand.Next(bmp.Height));
    SKPoint pt2 = new(rand.Next(bmp.Width), rand.Next(bmp.Height));
    paint.StrokeWidth = rand.Next(1, 10);
    canvas.DrawLine(pt1, pt2, paint);

// Save the image to disk
SKFileWStream fs = new("quickstart.jpg");
bmp.Encode(fs, SKEncodedImageFormat.Jpeg, quality: 85);