---
title: "Blur an image in C#"
url: https://recursiveai.org/oneimage/cookbook/blur-image/
description: "Apply Gaussian blur in C# with OneImage. Set sigma, blur on transparency, and choose horizontal or vertical smoothing with a runnable .NET example."
version: "1.11.1"
---

# Blur an image in C#

**OneImage** is a free, open-source image library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneImage) · [GitHub](https://github.com/recursive-ai-oss/oneimage-csharp) · [Docs](https://recursiveai.org/oneimage/docs/) · [Download example (.zip)](https://recursiveai.org/oneimage/cookbook/blur-image/blur-image.zip)

Gaussian blur softens detail by blending neighboring pixels.

```shell
dotnet add package RecursiveAI.OneImage
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using OneImage;

// input.png is in the zip.
Image.Load("input.png")
    .GaussianBlur(sigma: 3)
    .Save("blurred.png");
Console.WriteLine("Wrote blurred.png");
```

```text
Wrote blurred.png
```

Unzip [the example](https://recursiveai.org/oneimage/cookbook/blur-image/blur-image.zip), then `dotnet run`.

## The full program

The example creates a 200 × 140 white image with a blue rectangle, a red stripe, and a 20-pixel border. The pixel construction below defines the complete input, so you can also run it without a sample file.

```csharp
using OneImage;

// Blue rectangle with a red stripe on white.
const int width = 200, height = 140;
var pixels = new Rgba32[width * height];
var white = new Rgba32(255, 255, 255, 255);
var blue = new Rgba32(20, 100, 220, 255);
var red = new Rgba32(220, 40, 30, 255);
for (int y = 0; y < height; y++)
for (int x = 0; x < width; x++)
{
    bool inside = x >= 20 && x < 180
        && y >= 20 && y < 120;
    bool stripe = x >= 90 && x < 110;
    pixels[y * width + x] = inside
        ? (stripe ? red : blue)
        : white;
}
Image.FromPixels<Rgba32>(pixels, width, height)
    .Save("input.png");

Image blurred = Image.Load("input.png")
    .GaussianBlur(sigma: 3);
blurred.Save("blurred.png");
Console.WriteLine(
    $"blurred.png: {blurred.Width}" +
    $"x{blurred.Height}");
```

`dotnet run` prints:

```text
blurred.png: 200x140
```

`GaussianBlur` builds a lazy operation; `Save` evaluates it and writes the PNG. Invalid sigma values throw `ArgumentOutOfRangeException`.

## Variations

**Horizontal blur.** Set a separate vertical sigma to leave that axis unchanged:

```csharp
using OneImage;

Image.Load("input.png")
    .GaussianBlur(sigma: 6, sigmaY: 0)
    .Save("horizontal.png");
Console.WriteLine("Wrote horizontal.png");
```

```text
Wrote horizontal.png
```

**Reflect the edges.** This uses reflected pixels outside the image instead of repeating its last pixel:

```csharp
using OneImage;

Image.Load("input.png")
    .GaussianBlur(sigma: 3, edge: EdgeMode.Mirror)
    .Save("mirror.png");
Console.WriteLine("Wrote mirror.png");
```

```text
Wrote mirror.png
```

## Related recipes

- [Remove a uniform image border](https://recursiveai.org/oneimage/cookbook/trim-image-border/)
- [Apply a perspective transform](https://recursiveai.org/oneimage/cookbook/perspective-transform-image/)
- [Create a thumbnail](https://recursiveai.org/oneimage/cookbook/create-thumbnail/)

## The short answer

Load an image with `Image.Load`, call `GaussianBlur(sigma: 3)`, and save the returned image. The original is not overwritten unless you choose its path as the destination. This operation keeps the image dimensions and applies to every frame, so an animated input is not reduced to its first frame by the blur itself. Choose an output format that supports frames if you need to keep them.

## How do I blur an image in C#?

The snippet at the top is a complete file-based example. It reads `input.png`, softens the full image, and writes `blurred.png`. You don’t need to construct a convolution kernel or copy pixels into a second buffer yourself. The full program generates a small input with sharp rectangle edges that make the smoothing visible.

A Gaussian blur weights nearby pixels more heavily than distant pixels. Sigma is the standard deviation in pixels, not a percentage and not a target image size. Start with a small sigma, inspect the saved image at its intended display size, and increase it if you need more smoothing. Resizing afterward also changes how large the blur appears on screen.

OneImage defaults to the same sigma on both axes. The horizontal variation sets `sigmaY: 0`, so it smooths across columns without smoothing between rows. Setting both axes to zero returns the original image unchanged. Negative or nonfinite sigma values are invalid.

### How does Gaussian blur handle transparency?

OneImage’s [filter documentation](https://recursiveai.org/oneimage/docs/guide/#filters) specifies linear-light processing on premultiplied alpha by default. Color is multiplied by coverage before neighboring pixels are mixed, and alpha is blurred too. This avoids dark halos from blending an object with the unused color values of transparent pixels.

Use PNG when you need to retain transparency. `linear: false` switches color mixing to the stored values, but still premultiplies alpha. It does not mean “ignore transparency.”

The default edge mode repeats the boundary pixel. `EdgeMode.Mirror`, shown above, reflects the image at its boundary. `EdgeMode.Constant` supplies transparent black outside the image. `EdgeMode.Wrap` is not supported for this filter.

## Is Gaussian blur expensive?

The work depends on both the image and the blur width. OneImage evaluates filters lazily, reading the tiles and neighboring margins it needs when you render or save. The [published API](https://github.com/recursive-ai-oss/oneimage-csharp/blob/a0650f30eb30585a927ff4af0ae7d7e1dc7400cf/src/OneImage/Image.Filter.cs) describes exact filtering through sigma 16 and a reduced-resolution approximation for larger sigma values. A very wide blur therefore follows a different processing path; it is not simply an arbitrarily large exact kernel.

Choose sigma for the visual result, rather than treating a large value as a quality setting. Gaussian blur is an image effect, not a promise that information has been irreversibly removed. This recipe does not provide privacy redaction.
