Image Processing in C# (.NET): Libraries and Code Examples

Online Python Trainer for Beginners

Learn Python easily without overwhelming theory. Solve practical tasks with automatic checking, get hints in Russian, and write code directly in your browser — no installation required.

Start Course

Working with Images in C# (.NET): Library Overview and Practical Examples

Image processing is one of the key tasks when creating modern web applications, desktop programs, and mobile services. In the C# (.NET) ecosystem, there are several powerful libraries that allow you to load, edit, analyze, and save images. In this article, we will cover the main approaches: from the classic System.Drawing to modern cross-platform solutions ImageSharp and SkiaSharp.



1. System.Drawing.Common — .NET Classic

The System.Drawing.Common library is available in .NET Core/.NET 5+ as a NuGet package. It provides a familiar API for working with raster images (BMP, JPEG, PNG, GIF, TIFF).
Important: on Linux and macOS, it requires the libgdiplus library to be installed.



Installation

dotnet add package System.Drawing.Common


Example: Loading, Resizing, and Saving

using System.Drawing;using System.Drawing.Drawing2D;using System.Drawing.Imaging;

public class ImageProcessor{ public void ResizeImage(string inputPath, string outputPath, int maxWidth, int maxHeight) { using var original = Image.FromFile(inputPath); var ratio = Math.Min((double)maxWidth / original.Width, (double)maxHeight / original.Height); int newWidth = (int)(original.Width * ratio); int newHeight = (int)(original.Height * ratio);

using var bitmap = new Bitmap(newWidth, newHeight); using var graphics = Graphics.FromImage(bitmap); graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.DrawImage(original, 0, 0, newWidth, newHeight);

bitmap.Save(outputPath, ImageFormat.Jpeg); }}


2. ImageSharp (SixLabors) — Modern Cross-Platform Library

SixLabors.ImageSharp is a pure managed library with no dependencies on native components. It is ideal for server applications, web services, and cloud functions. Supports advanced formats (WebP, HEIF, AVIF) and advanced processing.



Installation

dotnet add package SixLabors.ImageSharp


Example: Adding a Watermark

using SixLabors.ImageSharp;using SixLabors.ImageSharp.Drawing.Processing;using SixLabors.ImageSharp.Processing;using SixLabors.Fonts;

public async Task AddWatermarkAsync(string inputPath, string outputPath, string watermarkText){ using var image = await Image.LoadAsync(inputPath); var font = SystemFonts.CreateFont("Arial", 48, FontStyle.Bold);

image.Mutate(ctx => { ctx.DrawText(watermarkText, font, Color.White, new PointF(50, 50)); });

await image.SaveAsync(outputPath);}


3. SkiaSharp — Graphics Engine from Google

SkiaSharp is a wrapper around the Skia library (used in Chrome, Flutter, Android). It provides high performance, low-level pixel access, and support for complex vector transformations.



Installation

dotnet add package SkiaSharp


Example: Applying a Blur Filter

using SkiaSharp;

public void ApplyBlur(string inputPath, string outputPath, float sigma){ using var inputStream = File.OpenRead(inputPath); using var original = SKBitmap.Decode(inputStream); using var surface = new SKCanvas(original);

var paint = new SKPaint { ImageFilter = SKImageFilter.CreateBlur(sigma, sigma) }; surface.DrawBitmap(original, 0, 0, paint);

using var image = SKImage.FromBitmap(original); using var data = image.Encode(SKEncodedImageFormat.Jpeg, 90); using var outputStream = File.OpenWrite(outputPath); data.SaveTo(outputStream);\

Recommendations